Example:
Code: Select all
(with-program-cases ((listp x) t)
(loop for y = x then #?((cdr y) (1+ y)) until #?((null y) (> y 5))
do(print y)))
Code: Select all
(cond ((listp x) (loop for y=x then (cdr y) until (null y) do(print y)))
(t (loop for y=x then (1+ y) until (> y 5) do(print y))))
In other words, each 'case' in the argument to the with-program-cases macro has a slight different
body, which is given by a list of different choices which is prefixed by the #? reader macro.
Preferably, i would also want to be able to define the macro so i could have something like this
#?([for y = x] [for y = 1])
where the brackets would indicate that for y=x and for y=1 would be pasted into the appropriate place without surrounding parentheses. But that's for another time!
I figured i would implement this by making the reader macro #? append the appropriate data to two global variables
, *cases* and *case-vars*. The macro with-program-cases would then use this data to expand into an intermediate state given by the following (using the first example above):
Code: Select all
(COND ((LISTP X)
(SYMBOL-MACROLET ((#:G1757 (CDR X)) (#:G1761 (NULL Y)))
(LOOP FOR Y = X THEN #:G1757 UNTIL #:G1761)))
(T (SYMBOL-MACROLET ((#:G1757 (1+ Y)) (#:G1761 (> Y 5)))
(LOOP FOR Y = X THEN #:G1757 UNTIL #:G1761))))
First, all the reader macros are expanded. When the with-program-cases is macroexpanded,
it now sees all the data pertaining to all the cases within each with-program-cases body. In other words, it has
no clue which data belongs to itself. So, what i need, i think, is either a totally different way to do this whole thing

or some way to communicate between the reader macros and the with-program-cases macro that surrounds them.
Thix!
