Thanks Neil and Richard !<div><br></div><div>Now that I look at your solutions, it looks so straightforward. Can't believe it didn't occur to me. <br><div><br></div><div><br><br><div class="gmail_quote">On Sat, Apr 30, 2011 at 7:31 AM, Neil Van Dyke <span dir="ltr"><<a href="mailto:neil@neilvandyke.org">neil@neilvandyke.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">nikhil wrote at 04/30/2011 03:16 AM:<div class="im"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
In my case, I have an incoming function which takes 4 arguments and I need to generate a function which takes in 5 args when a condition satisfies, if not then the original 4 args .<br>
</blockquote>
<br></div>
>From looking at the example you provided, two ways come to mind immediately. Either way is fine. Which you use depends on the circumstances, including code maintainability.<br>
<br>
#lang racket<br>
<br>
(define (f? x)<br>
;; This is just a placeholder for "f?".<br>
#t)<br>
<br>
(define (condition?)<br>
;; This is just a placeholder for "condition?".<br>
(zero? (random 2)))<br>
<br>
;; This uses ",@" splicing.<br>
(define (parse-func-1 exp)<br>
(let ((x1 'x1) (x2 'x2) (x3 'x3) (x4 'x4))<div class="im"><br>
(cond<br>
[(f? exp)<br>
`(FF<br>
,x1<br>
,x2<br>
,@(if (condition?)<br>
'(xNEW)<br>
'())<br>
,x3<br></div>
,x4)])))<br>
<br>
;; This moves the "if" higher up.<br>
(define (parse-func-2 exp)<br>
(let ((x1 'x1) (x2 'x2) (x3 'x3) (x4 'x4))<br>
(cond<br>
[(f? exp)<br>
(if (condition?)<br>
`(FF<div class="im"><br>
,x1<br>
,x2<br>
xNEW<br>
,x3<br>
,x4)<br></div>
`(FF<br>
,x1<br>
,x2<br>
,x3<br>
,x4))])))<br><font color="#888888">
<br>
<br>
<br>
-- <br>
<a href="http://www.neilvandyke.org/" target="_blank">http://www.neilvandyke.org/</a><br>
</font></blockquote></div><br></div></div>