unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* macroexpand-all and cl-macrolet
@ 2013-08-17 19:25 Nic Ferrier
  2013-08-19  2:51 ` Stefan Monnier
  2013-08-19 12:08 ` Wolfgang Jenkner
  0 siblings, 2 replies; 4+ messages in thread
From: Nic Ferrier @ 2013-08-17 19:25 UTC (permalink / raw)
  To: emacs-devel

Is macroexpand-all not supposed to work with macrolet?

  (progn
    (cl-macrolet 
        ((nlet (bindings &rest body)
           `(apply
             (lambda ,(mapcar 'car bindings) ,@body)
             (list ,@(mapcar 'cadr bindings)))))
      (macroexpand-all
       '(nlet ((a 1)
               (b '(10)))
         (* a (car b)))))) 

   =>  (nlet ((a 1)
              (b (quote (10))))
         (* a (car b)))

which surprised me a bit.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: macroexpand-all and cl-macrolet
  2013-08-17 19:25 macroexpand-all and cl-macrolet Nic Ferrier
@ 2013-08-19  2:51 ` Stefan Monnier
  2013-08-19 12:08 ` Wolfgang Jenkner
  1 sibling, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2013-08-19  2:51 UTC (permalink / raw)
  To: Nic Ferrier; +Cc: emacs-devel

> Is macroexpand-all not supposed to work with macrolet?

Depends what you mean.

>   (progn
>     (cl-macrolet 
>         ((nlet (bindings &rest body)
>            `(apply
>              (lambda ,(mapcar 'car bindings) ,@body)
>              (list ,@(mapcar 'cadr bindings)))))
>       (macroexpand-all
>        '(nlet ((a 1)
>                (b '(10)))
>          (* a (car b)))))) 

>    =>  (nlet ((a 1)
>               (b (quote (10))))
>          (* a (car b)))

cl-macrolet says that nlet will be bound as a macro during
macroexpansion of

    (macroexpand-all
        '(nlet ((a 1)
                (b '(10)))
          (* a (car b))))

But macroexpand-all will not run during the macroexpansion of
that expression.  After all, it's a plain function that will only be run
later after its macro-expansion is over.

So macroexpand-all will only get to look at the `nlet' call when that
code is *run* at which point the `nlet' definition provided by macrolet
is "long gone".


        Stefan



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: macroexpand-all and cl-macrolet
  2013-08-17 19:25 macroexpand-all and cl-macrolet Nic Ferrier
  2013-08-19  2:51 ` Stefan Monnier
@ 2013-08-19 12:08 ` Wolfgang Jenkner
  2013-08-19 18:14   ` Nic Ferrier
  1 sibling, 1 reply; 4+ messages in thread
From: Wolfgang Jenkner @ 2013-08-19 12:08 UTC (permalink / raw)
  To: Nic Ferrier; +Cc: emacs-devel

On Sat, Aug 17 2013, Nic Ferrier wrote:

> Is macroexpand-all not supposed to work with macrolet?
>
>   (progn
>     (cl-macrolet 
>         ((nlet (bindings &rest body)
>            `(apply
>              (lambda ,(mapcar 'car bindings) ,@body)
>              (list ,@(mapcar 'cadr bindings)))))
>       (macroexpand-all
>        '(nlet ((a 1)
>                (b '(10)))
>          (* a (car b)))))) 
>
>    =>  (nlet ((a 1)
>               (b (quote (10))))
>          (* a (car b)))

However, the following form evaluates to the desired expansion of nlet.
It is inspired by the description of `macroexpand' in the CLHS, in
particular by the remark about `macrolet' and the examples given there,
see

http://www.lispworks.com/documentation/HyperSpec/Body/f_mexp_.htm

(progn
  (require 'cl-lib)

  (cl-defmacro macroexpand-all-locally (form &environment env)
    `(macroexpand-all ,form ',env))

  (cl-macrolet
      ((nlet (bindings &rest body)
	     `(apply
	       (lambda ,(mapcar 'car bindings) ,@body)
	       (list ,@(mapcar 'cadr bindings)))))
    (macroexpand-all-locally
     '(nlet ((a 1)
	     (b '(10)))
	    (* a (car b))))))


Wolfgang



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: macroexpand-all and cl-macrolet
  2013-08-19 12:08 ` Wolfgang Jenkner
@ 2013-08-19 18:14   ` Nic Ferrier
  0 siblings, 0 replies; 4+ messages in thread
From: Nic Ferrier @ 2013-08-19 18:14 UTC (permalink / raw)
  To: emacs-devel

Wolfgang Jenkner <wjenkner@inode.at> writes:

> On Sat, Aug 17 2013, Nic Ferrier wrote:
>
>> Is macroexpand-all not supposed to work with macrolet?
>>
>>   (progn
>>     (cl-macrolet 
>>         ((nlet (bindings &rest body)
>>            `(apply
>>              (lambda ,(mapcar 'car bindings) ,@body)
>>              (list ,@(mapcar 'cadr bindings)))))
>>       (macroexpand-all
>>        '(nlet ((a 1)
>>                (b '(10)))
>>          (* a (car b)))))) 
>>
>>    =>  (nlet ((a 1)
>>               (b (quote (10))))
>>          (* a (car b)))
>
> However, the following form evaluates to the desired expansion of nlet.
> It is inspired by the description of `macroexpand' in the CLHS, in
> particular by the remark about `macrolet' and the examples given there,
> see
>
> http://www.lispworks.com/documentation/HyperSpec/Body/f_mexp_.htm
>
> (progn
>   (require 'cl-lib)
>
>   (cl-defmacro macroexpand-all-locally (form &environment env)
>     `(macroexpand-all ,form ',env))
>
>   (cl-macrolet
>       ((nlet (bindings &rest body)
> 	     `(apply
> 	       (lambda ,(mapcar 'car bindings) ,@body)
> 	       (list ,@(mapcar 'cadr bindings)))))
>     (macroexpand-all-locally
>      '(nlet ((a 1)
> 	     (b '(10)))
> 	    (* a (car b))))))

That's brilliant Wolfgang, I don't understand it yet, but I have the
manual so I'll go find out.

Thanks again. 

PS, this is for an EmacsLisp->JavaScript compiler, so thanks for helping
to make such an abomination possible :-)


Nic



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-08-19 18:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-17 19:25 macroexpand-all and cl-macrolet Nic Ferrier
2013-08-19  2:51 ` Stefan Monnier
2013-08-19 12:08 ` Wolfgang Jenkner
2013-08-19 18:14   ` Nic Ferrier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).