Closures/Value capture: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|F#}}: Regularize header markup to recommended on category page) |
(Emacs Lisp: Use lexical binding rather than lexical-let) |
||
Line 631: | Line 631: | ||
=={{header|Emacs Lisp}}== |
=={{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 #'funcall |
||
(mapcar (lambda (x) |
|||
(lambda () |
|||
(lexical-let ((x x)) |
|||
(* x x))) |
|||
'(1 2 3 4 5 6 7 8 9 10))) |
|||
;; => (1 4 9 16 25 36 49 64 81 100) |
;; => (1 4 9 16 25 36 49 64 81 100) |
||
</lang> |
</lang> |