Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -1,11 +1,10 @@
|
|||
#define system.
|
||||
#define system'routines.
|
||||
|
||||
#symbol PrintSecondPower =
|
||||
(:n) [ console writeLine:(n * n) ].
|
||||
|
||||
#symbol program =
|
||||
[
|
||||
#var anArray := (1, 2, 3, 4, 5, 6, 7, 8, 9, 10).
|
||||
|
||||
control foreach:anArray &do:PrintSecondPower.
|
||||
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) run &each:PrintSecondPower.
|
||||
].
|
||||
|
|
|
|||
|
|
@ -1,16 +1,19 @@
|
|||
my $function = { 2 * $^x + 3 };
|
||||
sub function { 2 * $^x + 3 };
|
||||
my @array = 1 .. 5;
|
||||
|
||||
# via map function
|
||||
.say for map $function, @array;
|
||||
.say for map &function, @array;
|
||||
|
||||
# via map method
|
||||
.say for @array.map($function);
|
||||
.say for @array.map(&function);
|
||||
|
||||
# via for loop
|
||||
for @array {
|
||||
say $function($_);
|
||||
say function($_);
|
||||
}
|
||||
|
||||
# via the "hyper" metaoperator and method indirection
|
||||
say @array».$function;
|
||||
say @array».&function;
|
||||
|
||||
# we neither need a variable for the array nor for the function
|
||||
say [1,2,3]>>.&({ $^x + 1});
|
||||
|
|
|
|||
|
|
@ -1,29 +1,26 @@
|
|||
/*REXX program to apply a callback to a stemmed (REXX) array. */
|
||||
a.=; b.=
|
||||
a.0= 0
|
||||
a.1= 1
|
||||
a.2= 2
|
||||
a.3= 3
|
||||
a.4= 4
|
||||
a.5= 5
|
||||
a.6= 6
|
||||
a.7= 7
|
||||
a.8= 8
|
||||
a.9= 9
|
||||
a.10=10
|
||||
|
||||
call listab 'before'
|
||||
call bangit 'a','b' /*factorialize the A array, store results in B */
|
||||
call listab ' after'
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────BANGIT subroutine───────────────────*/
|
||||
bangit: do i=0
|
||||
_=value(arg(1)'.'i); if _=='' then return
|
||||
call value arg(2)'.'i,fact(_)
|
||||
/*REXX pgm applies a callback to an array (using factorials for demonstration)*/
|
||||
a.=; b.=; a.0 = 0
|
||||
a.1 = 1
|
||||
a.2 = 2
|
||||
a.3 = 3
|
||||
a.4 = 4
|
||||
a.5 = 5
|
||||
a.6 = 6
|
||||
a.7 = 7
|
||||
a.8 = 8
|
||||
a.9 = 9
|
||||
a.10 = 10
|
||||
call listAB 'before'
|
||||
call bangit 'a','b' /*factorialize the A array, store results───►B.*/
|
||||
call listAB ' after'
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*────────────────────────────────────────────────────────────────────────────*/
|
||||
bangit: do i=0; _=value(arg(1)'.'i); if _=='' then return
|
||||
call value arg(2)'.'i, fact(_)
|
||||
end /*i*/
|
||||
/*──────────────────────────────────FACT subroutine─────────────────────*/
|
||||
fact: procedure; !=1; do j=2 to arg(1); !=!*j; end; return !
|
||||
/*──────────────────────────────────LISTAB subroutine───────────────────*/
|
||||
listab: do j=0 while a.j\==''; say arg(1) 'a.'j"="a.j; end /*j*/
|
||||
say; do k=0 while b.k\==''; say arg(1) 'b.'k"="b.k; end /*k*/
|
||||
/*────────────────────────────────────────────────────────────────────────────*/
|
||||
fact: procedure; !=1; do j=2 to arg(1); !=!*j; end; return !
|
||||
/*────────────────────────────────────────────────────────────────────────────*/
|
||||
listAB: do j=0 while a.j\==''; say arg(1) 'a.'j"="a.j; end /*j*/; say
|
||||
do k=0 while b.k\==''; say arg(1) 'b.'k"="b.k; end /*k*/
|
||||
return
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
fn echo(n: &i32) {
|
||||
println!("{}", n);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let a: [i32; 5];
|
||||
a = [1, 2, 3, 4, 5];
|
||||
let _: Vec<_> = a.into_iter().map(echo).collect();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue