<div dir="ltr"><div>Ah, very good, that's much better. Mystery solved.<br></div><div>(though I do kind of like the `and-let' with `#:let' keywords, since it avoids the paren-verbosity of `let'.)<br></div><div>
<br></div>Thanks ëÌÏÞËÏ× and Matthias,<br>Laurent<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jun 11, 2013 at 8:44 PM, Matthias Felleisen <span dir="ltr"><<a href="mailto:matthias@ccs.neu.edu" target="_blank">matthias@ccs.neu.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><br></div><div>Nice, I wish Oleg had also defined let*-and, which is what I think you really want here:š</div>
<div><br></div><div><div>(define-syntax let*-and</div><div>š (syntax-rules ()</div><div>š š [(_ ((x:id e:expr) (y:id f:expr) ...) body0:def-or-expr body1 ...)</div><div>š š š(let ((x:id e:expr))</div><div>š š š š(and x:id (let*-and ((y:id f:expr) ...) body0:def-or-expr body1 ...)))]</div>
<div>š š [(_ ((x:id) (y:id f:expr) ...) body0:def-or-expr body1 ...)</div><div>š š š(let ((x:id x:id))</div><div>š š š š(and x:id (let*-and ((y:id f:expr) ...) body0:def-or-expr body1 ...)))]</div><div>š š [(_ () body0:def-or-expr body1 ...)</div>
<div>š š š(let ()</div><div>š š š šbody0:def-or-expr</div><div>š š š šbody1 ...)]))</div><div><br></div><div>;; ----------------------------------------------------------------</div><div><br></div><div>(class object%š</div>
<div>š (super-new)</div><div>šš</div><div>š (define/private (get-x-spot.v2 char-width)</div><div>š š (let*-andš([char-width]</div><div class="im"><div>š š š š š š š š š š [dc (get-dc)]</div><div>š š š š š š š š š š [style (or (send (get-style-list) find-named-style "Standard")</div>
<div>š š š š š š š š š š š š š š š š š (send (get-style-list) find-named-style "Basic"))])</div></div><div>š š š š (define-values (fnt) (send style get-font))</div><div class="im"><div>š š š š (define-values (xw _1 _2 _3) (send dc get-text-extent "x" fnt))</div>
</div><div>š š š š (+ left-padding (* xw char-width)))))</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>-- Matthias</div><div><br></div><div>šš</div></font></span></div><div><div class="h5"><div><br>
</div>
<br><div><div>On Jun 11, 2013, at 1:39 PM, ëÌÏÞËÏ× òÏÍÁÎ wrote:</div><br><blockquote type="cite">
<div>You may use srfi/2š<a href="http://docs.racket-lang.org/srfi-std/srfi-2.html" target="_blank">http://docs.racket-lang.org/srfi-std/srfi-2.html</a><br><br>(require srfi/2)<br><span style="font-family:'courier new',monospace">(define (get-x-spot char-width)</span><br style="font-family:'courier new',monospace">
<span style="font-family:'courier new',monospace">š (and-let*</span><br style="font-family:'courier new',monospace"><span style="font-family:'courier new',monospace">š š([char-width]</span><br style="font-family:'courier new',monospace">
<span style="font-family:'courier new',monospace">š š [dc (get-dc)]</span><br style="font-family:'courier new',monospace"><span style="font-family:'courier new',monospace">š š [style (or (send (get-style-list) find-named-style "Standard")</span><br style="font-family:'courier new',monospace">
<span style="font-family:'courier new',monospace">šššššššššššššššššššššš (send (get-style-list) find-named-style "Basic"))])</span><br style="font-family:'courier new',monospace"><span style="font-family:'courier new',monospace">š š <span style="font-family:'courier new',monospace">(let*-values (</span>[(fnt) (send style get-font)]</span><br style="font-family:'courier new',monospace">
<span style="font-family:'courier new',monospace">š š š š š š š š š [(xw _1 _2 _3) (send dc get-text-extent "x" fnt)])</span><br style="font-family:'courier new',monospace"><span style="font-family:'courier new',monospace">šššššššššš (+ left-padding (* xw char-width))))))</span><br>
<br><br>÷ÔÏÒÎÉË, 11 ÉÀÎÑ 2013, 18:49 +02:00 ÏÔ Laurent <<a href="mailto:laurent.orseau@gmail.com" target="_blank">laurent.orseau@gmail.com</a>>:<br>
<blockquote style="border-left-width:1px;border-left-style:solid;border-left-color:rgb(8,87,166);margin-top:10px;margin-right:10px;margin-bottom:10px;margin-left:10px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:10px">
        <div>
        
        
        
        
        
        
        
        
<div>
        
        <div>
                
                
                        <div><div dir="ltr"><div><div><div><div><div><div><div>When I see what Robby is forced to write when following the Style:<br><a href="https://github.com/plt/racket/commit/09d636c54573522449a6591c805b38f72b6f7da8#L4R963" target="_blank">https://github.com/plt/racket/commit/09d636c54573522449a6591c805b38f72b6f7da8#L4R963</a><br>
</div><br>I cannot help but think that something is wrong somewhere (it may not be the Style, and in case it wasn't clear I'm certainly not criticizing Robby's code).<br></div><div></div>Using `let' and `and' instead, although<span style="font-family:courier new,monospace"><span style="font-family:arial,helvetica,sans-serif"> being a bit better since it avoids all the [else #f], is not that big an improvement:</span><br>
<br>(define (get-x-spot char-width)<br>š (and<br>šš char-width <br>šš (let ([dc (get-dc)])<br>šššš (and<br>ššššš dc<br>ššššš (let ([style (or (send (get-style-list) find-named-style "Standard")<br>šššššššššššššššššššššš (send (get-style-list) find-named-style "Basic"))])<br>
ššššššš (and<br>šššššššš style<br>šššššššš (let*-values ([(fnt) (send style get-font)]<br>šššššššššššššššššššššš [(xw _1 _2 _3) (send dc get-text-extent "x" fnt)])<br>šššššššššš (+ left-padding (* xw char-width)))))))))</span><br>
<br><br></div>Actually I think here the right thing to do might be to allow for internal definitions inside `and':<br><br><span style="font-family:courier new,monospace">(define (get-x-spot char-width)<br>š (and char-width<br>
šššššš (define dc (get-dc))<br>šššššš dc<br>šššššš (define style (or (send (get-style-list) find-named-style "Standard")<br>šššššššššššššššššššššššš (send (get-style-list) find-named-style "Basic")))<br>
šššššš style<br>šššššš (define fnt (send style get-font))<br>šššššš (define-values (xw _1 _2 _3) (send dc get-text-extent "x" fnt))<br>šššššš (+ left-padding (* xw char-width))))<br></span><br><br></div>Isn't it *much* more readable? (shorter, avoid rightward drift, less parens, vertical alignment)<br>
<br></div><div>Since it's not the first time I find the need for such internal definitions in `and', maybe this is something to consider for future addition to Racket? Or have some people already identified some problems with this idea?<br>
</div><div><br></div>I've played a bit with it if you want to try by your own:<br><a href="https://gist.github.com/Metaxal/5758394" target="_blank">https://gist.github.com/Metaxal/5758394</a><br><br></div>(not sure I got it all good with syntax-parse though)<br>
<br></div>Laurent<br><div><div><br></div></div></div>
</div>
                        <div>____________________<br>
ššRacket Users list:<br>
šš<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br>
</div>
                
                
        </div>
        
</div>
</div>
</blockquote>
<br>
<br>-- <br>òÏÍÁÎ ëÌÏÞËÏ×<br></div>
____________________<br> šRacket Users list:<br> š<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br></blockquote></div><br></div></div></div></blockquote></div><br></div>