elisp functions as parameters and as return value

前端 未结 2 1379
庸人自扰
庸人自扰 2021-01-02 05:26

I have the following code

(defun avg-damp(f) 
    #\'(lambda(x) (/ (+ (funcall f x) x) 2.0)))

A call

(funcall (avg-damp #         


        
2条回答
  •  走了就别回头了
    2021-01-02 05:51

    This style of programming does not work in plain Emacs Lisp. Emacs Lisp uses dynamic binding and languages like Scheme and Common Lisp are using lexical binding. Your code exposes the difference. See: Extent in Emacs Lisp

    See also this question: How do I do closures in Emacs Lisp? and the 'solution' with lexical-let. lexical-let is an extension for Emacs Lisp in the "cl" package.

    See also: since Emacs 24.1 there is optional lexical binding. Learn how to use it: using lexical binding.

提交回复
热议问题