Miles Bader <[EMAIL PROTECTED]> writes:

> On Mon, Nov 08, 2004 at 05:16:28PM +1100, Mark Triggs wrote:
>
>> Is there some easier way of doing this that we're missing?
>
> Hmmm, you might consider using a backquoted wrapper only for binding, and
> making the bulk of the lambda compilable, e.g.

[...]

>   (function-that-uses-lambda-later
>     `(lambda (args)
>        (let ((variable ,variable))
>          (funcall ,(lambda () (complicated code... variable))))))
>
> You could even make a macro to do this, like:
>
>    (defmacro lambda-with-constant-bindings (constants args &rest body)
>      "Like `lambda', with constant bindings for variables in CONSTANTS.
>    Any references in BODY to a variable listed in CONSTANTS will evaulate
>    to the binding in effect when the lambda was created, rather than at
>    the time it is called."
>      ``(lambda ,',args 
>        (let (,,@(mapcar (lambda (var) ``(,',var ',,var)) constants))
>          (funcall ,(lambda () ,@body)))))

This looks like a good solution, thanks.  Does anyone else have any
opinions on this?

Cheers,

Mark

-- 
Mark Triggs
<[EMAIL PROTECTED]>

Reply via email to