[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Code Generated by Macros
Date: Wed, 24 Apr 85 09:54:41 EST
From: greek@DEC-HUDSON
Did anyone out there write any of the Common LISP macro definitions
so that they generate DO, DOTIME, DOLIST or the like? Oops.
If the programmer uses a macro inside a construct that establishes
a block named NIL, and then does a RETURN from inside the macro,
there had better not be any blocks named NIL generated by the macro,
or the RETURN will return to the wrong place.
Not an obvious problem, and we blew it. Or maybe the idea of a block
named NIL is bogus.
I know what you are talking about, but I can't come up with an example
that can't be programmed around. For example,
(defmacro dotimes-named (name (var form) &body body)
`(block ,name
(return-from nil
(block do-return-from-nil
(return-from ,name
(dotimes (,var ,form)
(block dont-return-from-nil
(return-from do-return-from-nil
(block nil
,@body
(return-from dont-return-from-nil))))))))))
It isn't pretty, but it does work. I don't know if there are easier ways
to do this particular things. I have seen easier ways to other similar
things.
Perhaps it is for reasons like this that Lisp Machine Lisp has DO-NAMED?
That is, perhaps DO-NAMED is the prefered thing to expand into instead
of DO, since it won't accidentally steal the block named NIL?
Another way out is to document your macros as "having an implicit block
named NIL".