I'd like to use a function reference in place of a lambda
, however the lambda
in question captures a lot of locally scoped vars declared in an enclosing let
.
For example:
(let ((x 1)(y 2)(z 3)
(l '(1 2 3 4 5 6 7 8 9)))
(mapcar (lambda (i) (list x y z i)) l))
Let's assume the entire thing is way more complex, but is similar in essence. I'd want to move the lambda
out to a defun
, like this.
(defun fn (i)
"Function to use I in context."
(list x y z i))
(let ((x 1)(y 2)(z 3)
(l '(1 2 3 4 5 6 7 8 9)))
(mapcar 'fn l))
This doesn't work, x
y
z
are void (of course.)
Is there a way to make this possible? (Assume Emacs versions which allow lexical scope.)