Pascal Bourguignon <pjb@informatimago.com> wrote:
+---------------
| rpw3@rpw3.org (Rob Warnock) writes:
| > Peter Nagy <arrostia@elte.hu> wrote:
| > +---------------
| > | I've came up with a solution, which is this: ...[snipped]...
| > | I'm not satisfied with my solution, it seems to do the work
| > | but there's too much plumbing in it. How can it be done better?
| > +---------------
| >
...
| > Put that all together, and your code becomes much more readable:
|
| Unfortunately, you used TAB, so the code became much less readable:
+---------------
Hmmm... Sorry 'bout that. Not sure where the TABs came in -- I used
only spaces when indenting.
+---------------
| Why do you forbid: (key-if predicate-p :then :enabled :else :disabled) ?
+---------------
"I" didn't, Nagy's original code did. Not having access to the
problem statement he was solving, I didn't know if his specific
exclusion of other keywords was in the problem or not.
+---------------
| > Now it becomes clear that there's nothing preventing *multiple*
| > :THEN or :ELSE keywords from being used, with the forms following
| > each being accumulated into the corresponding IF branch, in order:
...
| > Is that what you would expect, given the problem statement?
|
| Why should there?
+---------------
See above about not having read the original problem statement
in the book. One might want to, in some case; one might not.
+---------------
| (defmacro key-if (test &body body)
| (loop ... ))
+---------------
Well, since he seemed to be a relative newbie, I decided *not*
to introduce LOOP myself. Had I used LOOP, I probably would have
done it much as you did.
+---------------
| There's no need to generate a IF, because the underlying Common Lisp
| implementation can do it for you:
+---------------
Yes, well, historically Lisp implementations have varied in
which of IF/COND is "primitive".
-Rob
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607