<div dir="ltr"><div class="gmail_extra">Antoine,<br><br></div><div class="gmail_extra">I'm changing the subject slightly to make a second thread, just to avoid confusion between the two set! questions.<br></div><div class="gmail_extra">
<br>I'm not sure I entirely understand why you're using set! to produce your results rather than simply returning them from the function. I believe you're saying it's because the function isn't tail recursive, but non-tail recursion will be equally as (in)efficient either way.<br clear="all">
<div><br></div><div>There are certainly some cases where it's more natural to use set! to accumulate a result than to build it up recursively, but they're the exception rather than the rule. I suggest trying to write your solution functionally first, and see how that goes. Resort to set! only if that fails somehow.<br>
</div><div><br>Carl Eastlund</div>
<br><div class="gmail_quote">On Fri, Jul 19, 2013 at 12:58 PM, Antoine Noo <span dir="ltr"><<a href="mailto:antoine597@gmail.com" target="_blank">antoine597@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><div><div><div><div><div>Hello,<br><br></div><div>as an extension of the question of Ben.<br></div><div><br></div>(define (func args)<br></div> (define result init-data)<br></div> (define (loop args-loop)<br>
...<br></div> (set! result some-data)<br> ....)<br></div> (loop args)<br></div> result)<br><div><div><div><br></div><div>Is this a good practice?<br></div><div>And if you ask why don't directly return loop, it is for the case to make recursive call every where in the function not only in terminal possition.<br>
</div></div></div></div></blockquote></div></div></div>