<div dir="ltr">If "thread-through macro" refers to "<a href="http://www.greghendershott.com/2013/05/the-threading-macro.html">http://www.greghendershott.com/2013/05/the-threading-macro.html</a>" then I recommend a functional alternative called "compose":<div><br></div><div><div>(define print/cdr</div><div>  (match-lambda</div><div>    [(cons x xs) (print x) xs]))</div><div><br></div><div>(define print-two</div><div>  (compose print/cdr print/cdr))</div></div><div><br></div><div>The result is chained through naturally since the input and output type of the lower level function are equal.</div><div><br></div><div>For any number of printings</div><div><br></div><div><div>(define (print-n n)</div><div>  (for/fold ([print-n identity])</div><div>            ([i n])</div><div>    (compose print/cdr print-n)))</div></div><div><br></div><div>(define print-two (print-n 2))</div><div><br></div><div>And for any number of anythings</div><div><br></div><div><div>(define (iterate f n)</div><div>  (for/fold ([chain identity])</div><div>            ([i n])</div><div>    (compose f chain)))</div><div><br></div><div>(define print-two (iterate print/cdr 2))</div></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 12, 2015 at 2:25 PM, Don Green <span dir="ltr"><<a href="mailto:infodeveloperdon@gmail.com" target="_blank">infodeveloperdon@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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>
<br>____________________<br>
  Racket Users list:<br>
  <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br></blockquote></div><br></div>