Not sure what you really want to have expanded and what you want in the result. I have found it helpful to begin with the end in mind.
Assuming you want the initial form to look like...
(FOO SOMESTUFF)
Can you provide an example, i.e. replace SOMESTUFF with some actual stuff.
Then for this example, what do you want the final form to look like after expansion?
Now defining the macro is a simple matter of programming. Outside of the define-macro, you can play with quasiquotes to get just the data looking the way you want it.
-Patrick
-----Original Message----- From: gambit-list-bounces@iro.umontreal.ca [mailto:gambit-list-bounces@iro.umontreal.ca] On Behalf Of Eric Merritt Sent: Tuesday, March 29, 2005 5:06 PM To: Gambit List Subject: [gambit-list] Problem using 'if' in a macro to conditionaly definea let form
Guys,
I am having a bit of a problem with if in a macro and I could use some help. Say I have a macro similar to the following
(define-macro (foo somestuff) `(let ((x ,sumstuff) ,(if (is-cool sumstuff) `(do-something-else-cool))) (some-more-stuff)))
this will result in an ill formed let anytime 'some-stuff' isn't cool. Thats becuase the 'if' statement returns #!void in the expansion which is invalid. Cond does the same thing. Is there an alternate way to do this, am I missing something obvious? I get the feeling that I am.
Thanks, Eric _______________________________________________ Gambit-list mailing list Gambit-list@iro.umontreal.ca http://mailman.iro.umontreal.ca/mailman/listinfo/gambit-list
Afficher les réponses par date
see inline ->
On Tue, 29 Mar 2005 17:16:29 -0800, Logan, Patrick D patrick.d.logan@intel.com wrote:
Not sure what you really want to have expanded and what you want in the result. I have found it helpful to begin with the end in mind.
(define-macro (foo somestuff) `(let ((x ,sumstuff) ,(if (is-cool sumstuff) `(z (do-something-else-cool)))) (some-more-stuff))
So this would preferably expand in two ways depending on what 'sumstuff' is
(let ((x avalue) (z (do-something-else-cool))) (some-more-stuff))
or
(let ((x avalue)) (some-more-stuff))
However, the second option is impossible because the above macro will expand to
(let ((x avalue) #!void) (some-more-stuff)))
in the face of an uncool 'sumstuff'. At least thats what it looks like is happening when I expand the macro.
Assuming you want the initial form to look like...
(FOO SOMESTUFF)
Can you provide an example, i.e. replace SOMESTUFF with some actual stuff.
Ok simple enough. So lets say sumstuff is
'((cool 33) (not-cool 44))
and is-cool is defined as
(define (is-cool lst) (cond ((null? lst) #f) ((equal? 'cool (caar lst)) #t) (else (is-cool (cdr lst)))))
Then for this example, what do you want the final form to look like after expansion?
(let ((x avalue) (z (do-something-else-cool))) (some-more-stuff))
or
(let ((x avalue)) (some-more-stuff))
depending on the value of sumstuff
Now defining the macro is a simple matter of programming. Outside of the define-macro, you can play with quasiquotes to get just the data looking the way you want it.
Unfortunately, unless I am missing something big I can't for reasons stated above. Because although this
(let ((x avalue) (z (do-something-else-cool))) (some-more-stuff))
can be evaluated to just fine. I cannot get this
(let ((x avalue)) (some-more-stuff))
to result. In instances where sumstuff is (is-cool sumstuff) evaluates to false I get an ill-formed let error.