[gambit-list] Problem using 'if' in a macro to conditionaly definea let form
Eric Merritt
cyberlync at gmail.com
Tue Mar 29 20:49:39 EST 2005
see inline ->
On Tue, 29 Mar 2005 17:16:29 -0800, Logan, Patrick D
<patrick.d.logan at 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.
More information about the Gambit-list
mailing list