I wan't to implement a closure behavior in Elisp
, here is the code:
(setq lexical-binding t)
(setq var 3)
(require 'cl)
(defun foo (n)
#'(lambda (i)
(incf n i)))
(defvar bar (foo var))
(funcall bar 1)
what I want get is that every time I run the expr:(funcall bar 1)
it will increment the result of the expr by 1
. I don't know why it can't work, can someone explain it to me?
I found a similar question in the How do I do closures in Emacs Lisp? but I can't understand it. My Emacs version is 24.2.1 which seems support the lexical scoping
.