Closures/Value capture: Difference between revisions

Content added Content deleted
(Latitude language added)
Line 2,160: Line 2,160:
8=>64
8=>64
</pre>
</pre>

The above seems overly complicated. From TCL 8.5 onwards, lambda expressions are available - they are just two element lists, where the first element is a list of function arguments and the second holds the commands of the body of the function that use those arguments. Of course, TCL is about as dynamic as a language can get, so it's very easy to construct lambda functions that capture values:
<lang tcl>
for {set i 0} {$i < 10} {incr i} {lappend funcs "{} {puts $i}"}
foreach f [lrange $funcs 0 8] {apply $f}
</lang>


=={{header|TXR}}==
=={{header|TXR}}==