Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -0,0 +1,20 @@
|
|||
var f1 = function (x) { return x * 2; },
|
||||
f2 = function (x) { return x * x; },
|
||||
|
||||
fs = function (f, s) {
|
||||
return function (s) {
|
||||
return s.map(f);
|
||||
}
|
||||
},
|
||||
|
||||
fsf1 = fs(f1),
|
||||
fsf2 = fs(f2);
|
||||
|
||||
// Test
|
||||
[
|
||||
fsf1([0, 1, 2, 3]),
|
||||
fsf2([0, 1, 2, 3]),
|
||||
|
||||
fsf1([2, 4, 6, 8]),
|
||||
fsf2([2, 4, 6, 8])
|
||||
]
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
var f1 = function (x) { return x * 2; },
|
||||
f2 = function (x) { return x * x; },
|
||||
|
||||
fs = function (f) {
|
||||
return function () {
|
||||
return Array.prototype.slice.call(
|
||||
arguments
|
||||
).map(f);
|
||||
}
|
||||
},
|
||||
|
||||
fsf1 = fs(f1),
|
||||
fsf2 = fs(f2);
|
||||
|
||||
// Test alternative approach, with arbitrary numbers of arguments
|
||||
[
|
||||
fsf1(0, 1, 2, 3, 4),
|
||||
fsf2(0, 1, 2),
|
||||
fsf1(2, 4, 6, 8, 10, 12),
|
||||
fsf2(2, 4, 6, 8)
|
||||
]
|
||||
|
|
@ -3,9 +3,9 @@ sub fs ( Code $f, @s ) { @s.map: { .$f } }
|
|||
sub f1 ( $n ) { $n * 2 }
|
||||
sub f2 ( $n ) { $n ** 2 }
|
||||
|
||||
my &fsf1 := &fs.assuming: f => &f1;
|
||||
my &fsf2 := &fs.assuming: f => &f2;
|
||||
my &fsf1 := &fs.assuming(&f1);
|
||||
my &fsf2 := &fs.assuming(&f2);
|
||||
|
||||
for [1..3], [2, *+2 ... 8] X &fsf1, &fsf2 -> $s, $f {
|
||||
say ~ $f.($s);
|
||||
for [1..3], [2, 4 ... 8] X &fsf1, &fsf2 -> ($s, $f) {
|
||||
say $f.($s);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,23 @@
|
|||
/*REXX program demonstrates a method of partial function application. */
|
||||
s=; do a=0 to 3 /*build 1st series, low integers.*/
|
||||
s=strip(s a) /*append to the integer to S list*/
|
||||
/*REXX program demonstrates a method of a partial function application. */
|
||||
s=; do a=0 to 3 /*build 1st series of some low integers*/
|
||||
s=strip(s a) /*append to the integer to the S list*/
|
||||
end /*a*/
|
||||
|
||||
call fs 'f1',s; say 'for f1: series=' s", result=" result
|
||||
call fs 'f2',s; say 'for f2: series=' s", result=" result
|
||||
call fs 'f1',s; say 'for f1: series=' s", result=" result
|
||||
call fs 'f2',s; say 'for f2: series=' s", result=" result
|
||||
|
||||
s=; do b=2 to 8 by 2 /*build 2nd series, low even ints*/
|
||||
s=strip(s b) /*append to the integer to S list*/
|
||||
s=; do b=2 to 8 by 2 /*build 2nd series, low even integers. */
|
||||
s=strip(s b) /*append to the integer to the S list*/
|
||||
end /*b*/
|
||||
|
||||
call fs 'f1',s; say 'for f1: series=' s", result=" result
|
||||
call fs 'f2',s; say 'for f2: series=' s", result=" result
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────F1 subroutine───────────────────────*/
|
||||
f1: return arg(1)*2
|
||||
/*──────────────────────────────────F2 subroutine───────────────────────*/
|
||||
call fs 'f1',s; say 'for f1: series=' s", result=" result
|
||||
call fs 'f2',s; say 'for f2: series=' s", result=" result
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*────────────────────────────────────────────────────────────────────────────*/
|
||||
f1: return arg(1)* 2
|
||||
f2: return arg(1)**2
|
||||
/*──────────────────────────────────FS subroutine───────────────────────*/
|
||||
fs: procedure; arg f,s; $=; do j=1 for words(s); z=word(s,j)
|
||||
/*────────────────────────────────────────────────────────────────────────────*/
|
||||
fs: procedure; arg f,s; $=; do j=1 for words(s); z=word(s,j)
|
||||
interpret '$=$' f"("z')'
|
||||
end /*j*/
|
||||
return strip($)
|
||||
return strip($)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue