<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=us-ascii" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 11.00.9600.17690"></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=855571119-12032015><FONT color=#0000ff
size=2 face=Arial>#lang racket</FONT></SPAN></DIV>
<DIV> </DIV>
<DIV dir=ltr align=left><SPAN class=855571119-12032015><FONT color=#0000ff
size=2 face=Arial>(define (print-two f) (print (car f)) (print (cadr
f)))</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=855571119-12032015><FONT color=#0000ff
size=2 face=Arial>(print-two '(1 2)); prints 12</FONT></SPAN></DIV>
<DIV> </DIV>
<DIV dir=ltr align=left><SPAN class=855571119-12032015><FONT color=#0000ff
size=2 face=Arial>(define (print-all f) (for-each print f))<BR>(print-all '(1
2)); prints 12<BR>(print-all '(1 2 3 4)); prints 1234</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=855571119-12032015><FONT color=#0000ff
size=2 face=Arial></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=855571119-12032015><FONT color=#0000ff
size=2 face=Arial>Best wishes, Jos Koot</FONT></SPAN></DIV>
<DIV lang=en-us class=OutlookMessageHeader dir=ltr align=left>
<HR tabIndex=-1>
<FONT size=2 face=Tahoma><B>From:</B> users
[mailto:users-bounces@racket-lang.org] <B>On Behalf Of </B>Don
Green<BR><B>Sent:</B> jueves, 12 de marzo de 2015 19:25<BR><B>To:</B>
users@racket-lang.org<BR><B>Subject:</B> [racket] Looking for better designs to
learn principles.<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV dir=ltr>
<DIV>;Design A:<BR></DIV>;Rating: 1 out of 10<BR>;Poor because it uses set!<BR>
<DIV>
<DIV>(define print-two <BR> (lambda (f)<BR> (print (first
f))<BR> (set! f (rest f))<BR> (print (first
f))<BR> (set! f (rest f))<BR> f))<BR><BR>(void
(print-two '(1 2))) ;=> 12<BR>;-------------------------<BR>
<DIV>
<DIV>;Design B:<BR></DIV>
<DIV>;Rating: 2 out of 10<BR></DIV>;Better because it nests expressions to avoid
using set!<BR></DIV>
<DIV>;Poor because it less readable.<BR>(define print-two<BR> (lambda
(f)<BR> (print (first f))<BR> (print (first
(rest f)))<BR> f))<BR><BR>(void (print-two '(1 2))) ;=>
12<BR></DIV>
<DIV>When called in situations that allow one expression only, enclose call
within a 'begin' expression.<BR></DIV>
<DIV>;-------------------------<BR></DIV>
<DIV>;Design C:<BR></DIV>
<DIV>;Rating: 3 out of 10<BR></DIV>;Is this an even better design because it is
more readable than nesting expressions as in Design B above?<BR>
<DIV>(define (print-two f)<BR> (let* ([_ (print (first
f))]<BR> [f (rest
f)]<BR> [_ (print (first
f))]<BR> [f (rest
f)])<BR> f))<BR></DIV>(void (print-two '(1 2))) ;=>
12<BR>;-------------------------<BR></DIV>
<DIV>My questions are: <BR>"Can you recommend a better method?"<BR></DIV>
<DIV>"Can you recommend a better method using 'define with lambda'?"<BR>"Does
your better method use a macro?"<BR></DIV>
<DIV>"Does your better method use a thread-through macro?" If so, could
you please provide the definition of the thread-through macro.<BR></DIV>
<DIV>THANKS!<BR></DIV>
<DIV><BR></DIV></DIV></DIV></BODY></HTML>