<div dir="ltr"><div>Just for fun, if you have to use the value of the tests in several bodies, you may also define your own macro:<br><br>#lang racket<br><br>(define-syntax-rule (cond/let id [test body ...] ...)<br> (cond [test => (ë(id) body ...)]<br>
...))<br><br>(let ([x "123a" #;"123"])<br> (cond/let y <br> [(string->number x) (* y 10)]<br> [(regexp-match #px"\\da" x) y]<br> [#t y]))<br><br>
</div>
Of course, it's just a proof of concept, it doesn't handle `else' and one-expression clauses, it doesn't verify that id is an identifier, but you should get the idea.<br><br>Laurent<br><div><br></div></div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, May 24, 2013 at 6:19 PM, Eli Barzilay <span dir="ltr"><<a href="mailto:eli@barzilay.org" target="_blank">eli@barzilay.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">10 minutes ago, Don Green wrote:<br>
> It is possible to create a cond test-expr that also serves as the then-body,<br>
> however, this means that the expression would be executed twice.<br>
><br>
> This seems to be ill advised in principle.<br>
<br>
</div>`cond' can have one-expression clauses that serve both purposes:<br>
<br>
-> (cond [(printf "123\n")])<br>
123<br>
<br>
It's convenient to use in rare cases, but I usually try to avoid the<br>
temptation since it feels wartish...<br>
<div class="im"><br>
<br>
> Question: If it is ill-advised to create a cond test-expression that also<br>
> serves as the then body, then what function is recommend?<br>
><br>
> I am aware of the (cdr (or ... form.<br>
<br>
</div>(This looks like some assq use, which should benefit from the above.)<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:<br>
<a href="http://barzilay.org/" target="_blank">http://barzilay.org/</a> Maze is Life!<br>
</font></span><div class="HOEnZb"><div class="h5">____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</div></div></blockquote></div><br></div>