How do I do closures in Emacs Lisp?

后端 未结 8 1889
感动是毒
感动是毒 2020-12-01 03:12

I\'m trying to create a function on the fly that would return one constant value.

In JavaScript and other modern imperative languages I would use closures:



        
相关标签:
8条回答
  • 2020-12-01 03:41

    Stupid idea: how about:

    (defun foo (x)
      `(lambda () ,x))
    
    (funcall (foo 10))  ;; => 10
    
    0 讨论(0)
  • 2020-12-01 03:43

    Emacs lisp only has dynamic scoping. There's a lexical-let macro that approximates lexical scoping through a rather terrible hack.

    0 讨论(0)
提交回复
热议问题