lisp - how to return function in elisp -
this related question: elisp functions parameters , return value
(defun avg-damp (n) '(lambda(x) (/ n 2.0))) either
(funcall (avg-damp 6) 10) or
((avg-damp 6) 10) they gave errors of symbol's value variable void: n , eval: invalid function: (avg-damp 6) respectively.
the reason first form not work n bound dynamically, not lexically:
(defun avg-damp (n) (lexical-let ((n n)) (lambda(x) (/ x n)))) (funcall (avg-damp 3) 12) ==> 4 the reason second form not work emacs lisp is, common lisp, a "lisp-2", not "lisp-1"
Comments
Post a Comment