Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/Closures-Value-capture/Icon/closures-value-capture.icon
Normal file
15
Task/Closures-Value-capture/Icon/closures-value-capture.icon
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
procedure main(args) # Closure/Variable Capture
|
||||
every put(L := [], vcapture(1 to 10)) # build list of index closures
|
||||
write("Randomly selecting L[",i := ?*L,"] = ",L[i]()) # L[i]() calls the closure
|
||||
end
|
||||
|
||||
# The anonymous 'function', as a co-expression. Most of the code is standard
|
||||
# boilerplate needed to use a co-expression as an anonymous function.
|
||||
|
||||
procedure vcapture(x) # vcapture closes over its argument
|
||||
return makeProc { repeat { (x[1]^2) @ &source } }
|
||||
end
|
||||
|
||||
procedure makeProc(A) # the makeProc PDCO from the UniLib Utils package
|
||||
return (@A[1], A[1])
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue