<HTML><BODY>You may use srfi/2 <a href="http://docs.racket-lang.org/srfi-std/srfi-2.html" data-mce-href="http://docs.racket-lang.org/srfi-std/srfi-2.html">http://docs.racket-lang.org/srfi-std/srfi-2.html</a><br><br>(require srfi/2)<br><span style="font-family: 'courier new', monospace; " data-mce-style="font-family: 'courier new', monospace;">(define (get-x-spot char-width)</span><br style="font-family: 'courier new', monospace; " data-mce-style="font-family: 'courier new', monospace;"><span style="font-family: 'courier new', monospace; " data-mce-style="font-family: 'courier new', monospace;"> (and-let*</span><br style="font-family: 'courier new', monospace; " data-mce-style="font-family: 'courier new', monospace;"><span style="font-family: 'courier new', monospace; " data-mce-style="font-family: 'courier new', monospace;"> ([char-width]</span><br style="font-family: 'courier new', monospace; " data-mce-style="font-family: 'courier new', monospace;"><span style="font-family: 'courier new', monospace; " data-mce-style="font-family: 'courier new', monospace;"> [dc (get-dc)]</span><br style="font-family: 'courier new', monospace; " data-mce-style="font-family: 'courier new', monospace;"><span style="font-family: 'courier new', monospace; " data-mce-style="font-family: 'courier new', monospace;"> [style (or (send (get-style-list) find-named-style "Standard")</span><br style="font-family: 'courier new', monospace; " data-mce-style="font-family: 'courier new', monospace;"><span style="font-family: 'courier new', monospace; " data-mce-style="font-family: 'courier new', monospace;"> (send (get-style-list) find-named-style "Basic"))])</span><br style="font-family: 'courier new', monospace; " data-mce-style="font-family: 'courier new', monospace;"><span style="font-family: 'courier new', monospace; " data-mce-style="font-family: 'courier new', monospace;"> <span style="font-family: 'courier new', monospace; " data-mce-style="font-family: 'courier new', monospace;">(let*-values (</span>[(fnt) (send style get-font)]</span><br style="font-family: 'courier new', monospace; " data-mce-style="font-family: 'courier new', monospace;"><span style="font-family: 'courier new', monospace; " data-mce-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; " data-mce-style="font-family: 'courier new', monospace;"><span style="font-family: 'courier new', monospace; " data-mce-style="font-family: 'courier new', monospace;"> (+ left-padding (* xw char-width))))))</span><br><br><br>Вторник, 11 июня 2013, 18:49 +02:00 от Laurent <laurent.orseau@gmail.com>:<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; position: static; z-index: auto; " class="mailru-blockquote">
        <div id="">
        
        
        
        
        
        
        
        
<div class="js-helper js-readmsg-msg">
        <style type="text/css"></style>
        <div id="style_13709696130000000204" class="mr_read__body">
                <base target="_self" href="https://e.mail.ru/">
                
                        <div id="style_13709696130000000204_BODY"><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>
                
                <base target="_self" href="https://e.mail.ru/">
        </div>
        
</div>
</div>
</blockquote>
<br>
<br>-- <br>Роман Клочков<br></BODY></HTML>