How to overcome the lack of local variable for emacs lisp closure

前端 未结 4 1710
忘了有多久
忘了有多久 2021-02-08 02:53

I\'m now studying Emacs Lisp from the reference manual and Common Lisp from a LISP Book.

from the Common Lisp book

>> (setf power-of-two
     (let          


        
4条回答
  •  佛祖请我去吃肉
    2021-02-08 03:16

    another solution using Emacs' unintern symbol:

    ELISP> (setf power-of-two
             (let ((p (make-symbol "previous-power-of-two")))
               (set p 1) (list 'lambda '()
               (list 'setf p
                 (list '* p 2)))))
    
    ELISP> (funcall power-of-two)
    2
    ELISP> (funcall power-of-two)
    4
    ELISP> (funcall power-of-two)
    8
    

提交回复
热议问题