June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,8 +1,8 @@
|
|||
import system'routines.
|
||||
|
||||
program =
|
||||
public program =
|
||||
[
|
||||
var functions := Array new length:10; populate(:i)( [ ^ i * i ] ).
|
||||
var functions := Array new(10); populate(:i)<int>( [ ^ i * i ] ).
|
||||
|
||||
functions forEach(:func) [ console writeLine(func eval). ].
|
||||
functions forEach(:func) [ console writeLine(func()). ].
|
||||
].
|
||||
|
|
|
|||
1
Task/Closures-Value-capture/R/closures-value-capture-4.r
Normal file
1
Task/Closures-Value-capture/R/closures-value-capture-4.r
Normal file
|
|
@ -0,0 +1 @@
|
|||
evalq (x <- x + 1, parent.env(environment()))
|
||||
1
Task/Closures-Value-capture/R/closures-value-capture-5.r
Normal file
1
Task/Closures-Value-capture/R/closures-value-capture-5.r
Normal file
|
|
@ -0,0 +1 @@
|
|||
x <<- x + 1
|
||||
|
|
@ -1,13 +1,25 @@
|
|||
/*REXX program has a list of ten functions, each returns its invocation (index) squared.*/
|
||||
|
||||
do j=1 for 9; ?=random(0, 9) /*invoke random functions nine times.*/
|
||||
interpret 'CALL .'? /*invoke a randomly selected function. */
|
||||
end /*j*/ /* [↑] the called function has no args*/
|
||||
|
||||
say 'The tenth invocation of .0 ───► ' .0()
|
||||
parse arg seed base $ /*obtain optional arguments from the CL*/
|
||||
if datatype(seed, 'W') then call random ,,seed /*Not given? Use random start seed. */
|
||||
if base=='' | base="," then base=0 /* " " Use a zero─based list. */
|
||||
if $='' then $= 8 5 4 9 1 3 2 7 6 0 /* " " Use ordered function list*/
|
||||
/*the $ list must contain 10 functions.*/
|
||||
say 'the' word("zero one", base+1)'─based list is: ' $ /*show list of functions.*/
|
||||
/*BASED must be either 1 or 0. */
|
||||
?='.'random(0, 9) /*get a random name of a function. */
|
||||
interpret 'CALL' ? /*invoke a randomly selected function. */
|
||||
say 'function ' ? " returned " result /*display the value of random function.*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*───────────────────────────[Below is the closest thing to anonymous functions in REXX]*/
|
||||
.0: return .(); .1: return .(); .2: return .(); .3: return .(); .4: return .()
|
||||
.5: return .(); .6: return .(); .7: return .(); .8: return .(); .9: return .()
|
||||
/*────────────────────────[Below are the closest things to anonymous functions in REXX].*/
|
||||
.0: return .(0) /*function .0 ─── bump its counter. */
|
||||
.1: return .(1) /* ' .1 " " " " */
|
||||
.2: return .(2) /* ' .2 " " " " */
|
||||
.3: return .(3) /* ' .3 " " " " */
|
||||
.4: return .(4) /* ' .4 " " " " */
|
||||
.5: return .(5) /* ' .5 " " " " */
|
||||
.6: return .(6) /* ' .6 " " " " */
|
||||
.7: return .(7) /* ' .7 " " " " */
|
||||
.8: return .(8) /* ' .8 " " " " */
|
||||
.9: return .(9) /* ' .9 " " " " */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
.: if symbol('@')=="LIT" then @=0 /* ◄───handle very 1st invoke*/; @=@+1; return @*@
|
||||
.: arg #; _=wordpos(#,$); if _==0 then return 'not in the list.'; return (_-(\base))**2
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
funs: collect [repeat i 10 [keep func [] reduce [i ** 2]]]
|
||||
|
||||
>> funs/7
|
||||
== 49
|
||||
Loading…
Add table
Add a link
Reference in a new issue