[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Faking local dynamic function bindings
From: |
Stefan Monnier |
Subject: |
Re: Faking local dynamic function bindings |
Date: |
Wed, 29 Jan 2014 08:16:55 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
> This resembles an earlier version of my code, but AFAIU it has the
> disadvantage that the local macro binding is created and destroyed every
> time the anonymous function is executed, which I guess creates extra
> overhead and makes the function slower.
If that turns out to be a problem, you can do it as follows:
(defun foo (sexpr)
(let ((macroenv `((contains
. ,(lambda (regexp)
`(string-match ,regexp ,string))))))
(sort
(delq nil
(mapcar
(lambda (item)
(let ((string (assq item strings-alist)))
(when (eval (macroexpand-all sexpr macroenv))
string))
items-alist)))
#'string<)))
-- Stefan