<div dir="ltr"><div>I&#39;m also open to other solutions, but I find the (and (let (and (let (and ...))))) dance really inconvenient (verbose and not readable).<br><br>So maybe it can be made cleaner, like not use `define&#39; but `let&#39; (as I actually did), and maybe use a keyword as Ian does, to show that it is not a normal expression, e.g.:<br>

<span style="font-family:courier new,monospace">(define (get-x-spot char-width)<br>  (and char-width<br>       #:let dc (get-dc)<br>       dc<br>       #:let style (or (send (get-style-list) find-named-style &quot;Standard&quot;)<br>

                       (send (get-style-list) find-named-style &quot;Basic&quot;))<br>       style<br>       #:let fnt (send style get-font)<br>       #:let-values (xw _1 _2 _3) (send dc get-text-extent &quot;x&quot; fnt)<br>

       (+ left-padding (* xw char-width))))<br><br></span></div><div><span style="font-family:courier new,monospace"><span style="font-family:arial,helvetica,sans-serif">This way you would not need to care about the actual result of the `#:let&#39;s (and you could even add some `#:for-effect&#39; actions if you like ;).</span><br>

</span></div><br><div><div><div class="gmail_extra">Laurent<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jun 11, 2013 at 7:27 PM, Carl Eastlund <span dir="ltr">&lt;<a href="mailto:cce@ccs.neu.edu" target="_blank">cce@ccs.neu.edu</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>I don&#39;t have a big problem with the version that uses let.  But my point isn&#39;t really about the code quality, it&#39;s about the can of worms being opened with the specific proposed solution.  I&#39;m open to other solutions.<br>



<br></div>Also,
 re: definitions in and, bear in mind that definition macros do all 
kinds of crazy things.  Some might expand into multiple forms, including
 for-effect expressions.  That&#39;s another reason it&#39;s dangerous to put 
definitions into abnormal contexts that interpret them as anything other
 than a sequence of definitions and effects.  You don&#39;t want spurious 
(void) or (values) or some such to spoil your conditional.<span class=""><font color="#888888"><br>
<br clear="all"><div>Carl Eastlund<br><br></div></font></span><div><div class="h5"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jun 11, 2013 at 1:21 PM, Laurent <span dir="ltr">&lt;<a href="mailto:laurent.orseau@gmail.com" target="_blank">laurent.orseau@gmail.com</a>&gt;</span> wrote:<br>



<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div>Interesting, I see your point (not yet sure I adhere to it though).<br><br>



</div>Anyway don&#39;t you think there is a readability problem with the mentioned code?<span><font color="#888888"><br><br></font></span></div><span><font color="#888888">Laurent<br></font></span></div>

<div><div><div class="gmail_extra">

<br><br><div class="gmail_quote">On Tue, Jun 11, 2013 at 7:15 PM, Carl Eastlund <span dir="ltr">&lt;<a href="mailto:cce@ccs.neu.edu" target="_blank">cce@ccs.neu.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div dir="ltr"><div><div><div>I don&#39;t like the idea of definitions inside and, at all.  I&#39;ll elaborate on why.<br><br></div>Internal definitions and for-effect expressions make sense to me when computing a single result value, where the last form in sequence is the result and everything else is just context for that.<br>







<br></div>They do not make sense to me in function arguments and other similar contexts where, normally, each term&#39;s value contributes something to the result.  Every expression in a function application has a result that is used.  Every expression in an and form has a result that is used, if evaluation doesn&#39;t stop earlier.<br>







<br>If we started adding definitions to and, or, &amp;c., then suddenly I have to wonder which terms are used as definitions and which as arguments.  Worse yet, someone some day will want to put in an expression for effect in the middle of an and, and then we&#39;ll have some real chaos.<br>







<br></div>I&#39;m all for definitions anywhere they can be clearly seen as not part of the result form.  Let&#39;s not put them in between arguments whose results matter, please.<span><font color="#888888"><br>

</font></span></div><div class="gmail_extra"><span><font color="#888888"><br clear="all">

<div>Carl Eastlund</div>
<br><br></font></span><div class="gmail_quote"><div>On Tue, Jun 11, 2013 at 12:49 PM, Laurent <span dir="ltr">&lt;<a href="mailto:laurent.orseau@gmail.com" target="_blank">laurent.orseau@gmail.com</a>&gt;</span> wrote:<br>





</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><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&#39;t clear I&#39;m certainly not criticizing Robby&#39;s code).<br></div><div></div>Using `let&#39; and `and&#39; 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 &quot;Standard&quot;)<br>                       (send (get-style-list) find-named-style &quot;Basic&quot;))])<br>









        (and<br>         style<br>         (let*-values ([(fnt) (send style get-font)]<br>                       [(xw _1 _2 _3) (send dc get-text-extent &quot;x&quot; 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&#39;:<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 &quot;Standard&quot;)<br>                         (send (get-style-list) find-named-style &quot;Basic&quot;)))<br>









       style<br>       (define fnt (send style get-font))<br>       (define-values (xw _1 _2 _3) (send dc get-text-extent &quot;x&quot; fnt))<br>       (+ left-padding (* xw char-width))))<br></span><br><br></div>Isn&#39;t it *much* more readable? (shorter, avoid rightward drift, less parens, vertical alignment)<br>









<br></div><div>Since it&#39;s not the first time I find the need for such internal definitions in `and&#39;, 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&#39;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)<span><font color="#888888"><br>









<br></font></span></div><span><font color="#888888">Laurent<br><div><div><br></div></div></font></span></div>
<br></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></blockquote></div><br></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div></div></div></div>
</blockquote></div><br></div></div></div></div>