I want to use a function that is taking advantage of lexical-binding:
(defun comp (funcs)
"Function composition"
(let (f0 ff)
(if (not funcs)
(lambda (x &rest args)
x)
(progn
(setq f0 (car funcs))
(setq ff (cdr funcs))
(lambda (&rest args)
(funcall f0 (apply (comp ff) args)))))))
So setting (setq lexical-binding t)
inside my buffer and calling comp
with (funcall (comp (list (lambda (x) (* x 3)) (lambda (x) (+ 1 x)))) 0)
gives 3
as desired.
Now I want to move comp
to another lisp-file that gets loaded (via load-file
) from my .emacs
at the Emacs start-up. But then I get (void-variable f0)
which is not what I want. I included (setq lexical-binding t)
as a first line into .emacs
as well as the lisp-file containing comp
but this isn't solving my issue.
How can I resolve this without having to define my function comp
within the same buffer were I want to call it?