Closures/Value capture: Difference between revisions
Content added Content deleted
(Added LFE example) |
|||
Line 740:
</pre>
=={{header|LFE}}==
Input at the REPL:
<lang lisp>
> (set funcs (list-comp ((<- m (lists:seq 1 10)))
(lambda () (math:pow m 2))))
</lang>
Output:
<lang lisp>
(#Fun<lfe_eval.23.101079464> #Fun<lfe_eval.23.101079464>
#Fun<lfe_eval.23.101079464> #Fun<lfe_eval.23.101079464>
#Fun<lfe_eval.23.101079464> #Fun<lfe_eval.23.101079464>
#Fun<lfe_eval.23.101079464> #Fun<lfe_eval.23.101079464>
#Fun<lfe_eval.23.101079464> #Fun<lfe_eval.23.101079464>)
</lang>
Calling the functions:
<lang lisp>
> (funcall (car funcs))
1.0
> (funcall (cadr funcs))
4.0
> (funcall (cadddr funcs))
16.0
> (funcall (lists:nth 8 funcs))
64.0
</lang>
=={{header|Logtalk}}==
The example that follow uses Logtalk's native support for lambda expressions.
|