[Top][All Lists]

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

Re: Use the new let-opt macro in place of pcase-let in lisp-mode.el

From: Stefan Monnier
Subject: Re: Use the new let-opt macro in place of pcase-let in lisp-mode.el
Date: Mon, 18 May 2015 12:39:57 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

> As I understood, all this hassle is for not having to call `regexp-opt'
> at run-time, but instead at compile-time.

That's right (and it's particularly important here since this file is
preloaded, so calling it at runtime would require preloading regexp-opt
as well).

> For your consideration, I add a new macro named `let-opt' that is more
> efficient (I assume, `macroexpand' doesn't work properly for
> `pcase-let') than `pcase-let' in this case, and also much more simple
> and straightforward.

For this particular case, I think efficiency is of no importance, really.
And in their more general uses, these two macros are fairly unrelated.

> (defmacro let-opt (bindings &rest body)
>   "Like `let', but allows for compile time optimization.
> Expressions wrapped with `opt' will be subsituted for their values.
>   (declare (indent 1) (debug let))
>   (let ((bnd (mapcar (lambda (x) (cons (car x) (eval (cadr x))))
>                      bindings)))
>     `(cl-macrolet ((opt (&rest body)
>                         (list 'quote (eval (cons 'progn body) ',bnd))))
>        ,@body)))

I think I like this idea of "compile-time-only let-binding".
But I don't like this `opt' thingy very much and I think we can get rid
of it if we use dynamic-scoping instead.

IOW, define a let-when-compile macro which uses progv to setup the
bindings and then calls `macroexpand-all' on the body.  The body's
`eval-when-compile' can then use those vars just fine.


reply via email to

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