help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Macro Expansion Inconsistency


From: Nicolas Richard
Subject: Re: Macro Expansion Inconsistency
Date: Wed, 17 Dec 2014 15:21:18 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.2.0

Le 17/12/2014 15:03, Alexander Shukaev a écrit :
> Thank you very much, John and Nicolas. I think I finally understand
> how macros expand in Emacs Lisp better now. I'm sure it's not a
> coincidence that you both came up with almost identical solutions. It
> suggests that the style of returning forms for evaluation from macro
> is probably the best way to go in most cases when `let' is involved.

I hadn't seen John's answer. His solution is better than mine because
the (put ...) forms should indeed be included in the progn. (otherwise
they get executed at expansion time, and I think that'll not be good if
the code is byte-compiled.)

> As a final exam for myself, considering what I've learned, I've implemented a 
> collective definition macro as well:
> 
> (defmacro bm-define-flags
>     (name index character foreground &rest ...)
>   (let ((name       `,name)
>         (index      `,index)
>         (character  `,character)
>         (foreground `,foreground)
>         (...        `(,@...))

I think the above bindings are unnecessary.

>         (body       '()))
>     (while name
>       (push `(bm-define-flag ,name ,index ,character ,foreground) body)
>       (setq name       (pop ...)
>             index      (pop ...)
>             character  (pop ...)
>             foreground (pop ...)))
>     `(progn ,@body)))

Looks ok to me (but I'm not experienced).

> (put 'bm-define-flags 'lisp-indent-function 'defun)

I don't think that's useful for bm-define-flags. Btw you can also use a
(declare ...) form in your macro definition to achieve this goal.

-- 
Nicolas.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]