<div class="gmail_quote">On Sat, Feb 11, 2012 at 15:07, Rodolfo Carvalho <span dir="ltr"><<a href="mailto:rhcarvalho@gmail.com">rhcarvalho@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br><br><div class="gmail_quote">On Sat, Feb 11, 2012 at 14:55, Laurent <span dir="ltr"><<a href="mailto:laurent.orseau@gmail.com" target="_blank">laurent.orseau@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 class="im"><div><br></div><div>(define (bar [arg2 (get-default-value foo arg2)])</div><div> (foo 5 arg2))</div><div><br><br></div></div></blockquote><div><br>Maybe someone will have a better idea (or a brighter implementation), but if not, here's my contribution:<br>
<br>....</div></div></blockquote><div><br>If we use #f for arg2 in foo, we can write:<br><br>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<br>#lang racket<br>(require rackunit)<br><br>(define (foo arg1 [arg2 #f])<br> (+ arg1 (or arg2 10)))<br>
<br>(define (bar [arg2 #f])<br> (let ([arg1 5])<br> (foo arg1 arg2)))<br><br>(check-= (bar 2) 7 0)<br>(check-= (bar) 15 0) <br></div></div>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<br><br>This way it is not necessary to accommodate for calling foo with different number of args. All we need is to propagate the #f default value.<br>
<br><br>[]'s<br><br>Rodolfo<br>