[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: A macro and an unwanted containing list in the resulting form
From: |
Pascal Bourguignon |
Subject: |
Re: A macro and an unwanted containing list in the resulting form |
Date: |
Thu, 24 May 2007 01:48:12 +0200 |
User-agent: |
Gnus/5.1008 (Gnus v5.10.8) Emacs/22.0.99 (gnu/linux) |
Sebastian Tennant <sebyte@smolny.plus.com> writes:
>> And finally, it would be better if we could have several forms in each
>> branches, and if we lost the dot:
>
> "lost the dot" = "do without cons cells" -----+
> |
> +--------
> |
> \/
>> (defmacro string-case (strexpr &rest alist)
>> (let ((var-name (gensym)))
>> `(let ((,var-name ,strexpr))
>> (cond ,@(mapcar (lambda (each)
>> `((equal ,var-name ,(car each)) ,@(cdr each)))
>> alist))))) ^
> |
> I see. ----------------------------------------------------+--+
> |
>> (macroexpand '(string-case (aref my-strings (incf i)) |
>> ("hello" (message "hi") (message "ho")) |
>> ("goodbye" (message "bye")))) |
> |
> Unique variable name created by (gensym) ---+ |
> | |
> ---------------------------------+ |
> | |
> \/ |
>> (let ((G42298 (aref my-strings (incf i)))) |
>> (cond |
>> ((equal G42298 "hello") |
>> (message "hi") (message "ho")) <--+---------------------+
>> ((equal G42298 "goodbye") |
>> (message "bye")))) |
> |
> "several forms in each branch" ----------+
>
> Well Pascal, thank you for an excellent crash-course in macro
> expansion!
>
> I hope my annotations are correct, and not out of place, although
> people not reading this in a fixed-with font will no doubt wonder what
> on earth is going on, not to mention the other nasty things
> line-wrapping news-manglers are inclined to do!
They're correct.
--
__Pascal Bourguignon__ http://www.informatimago.com/
NOTE: The most fundamental particles in this product are held
together by a "gluing" force about which little is currently known
and whose adhesive power can therefore not be permanently
guaranteed.
Re: A macro and an unwanted containing list in the resulting form, Pascal Bourguignon, 2007/05/23