Closures/Value capture: Difference between revisions

Emacs Lisp: Use lexical binding rather than lexical-let
m (→‎{{header|F#}}: Regularize header markup to recommended on category page)
(Emacs Lisp: Use lexical binding rather than lexical-let)
Line 631:
 
=={{header|Emacs Lisp}}==
As of Emacs 24.3, lexical closures are supported, therefore alleviating hacks such as lexical-let.
Emacs Lisp now has lexical-let, which allows for the capture of variables.
 
<lang lisp>
<lang lisp>;; -*- lexical-binding: t; -*-
(require 'cl)
(mapcar #'funcall
(mapcar (lambda (x)
(lambda ()
(lexical-let ((x x))
(lambda () (* x x)))) [1 2 3 4 5 6 7 8 9 10] (* x x)))
'(1 2 3 4 5 6 7 8 9 10)))
;; => (1 4 9 16 25 36 49 64 81 100)
</lang>
Anonymous user