Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
36
Task/Y-combinator/Chapel/y-combinator-1.chpl
Normal file
36
Task/Y-combinator/Chapel/y-combinator-1.chpl
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
proc fixz(f) {
|
||||
record InnerFunc {
|
||||
const xi;
|
||||
proc this(a) { return xi(xi)(a); }
|
||||
}
|
||||
record XFunc {
|
||||
const fi;
|
||||
proc this(x) { return fi(new InnerFunc(x)); }
|
||||
}
|
||||
const g = new XFunc(f);
|
||||
return g(g);
|
||||
}
|
||||
|
||||
record Facz {
|
||||
record FacFunc {
|
||||
const fi;
|
||||
proc this(n: int): int {
|
||||
return if n <= 1 then 1 else n * fi(n - 1); }
|
||||
}
|
||||
proc this(f) { return new FacFunc(f); }
|
||||
}
|
||||
|
||||
record Fibz {
|
||||
record FibFunc {
|
||||
const fi;
|
||||
proc this(n: int): int {
|
||||
return if n <= 1 then n else fi(n - 2) + fi(n - 1); }
|
||||
}
|
||||
proc this(f) { return new FibFunc(f); }
|
||||
}
|
||||
|
||||
const facz = fixz(new Facz());
|
||||
const fibz = fixz(new Fibz());
|
||||
|
||||
writeln(facz(10));
|
||||
writeln(fibz(10));
|
||||
48
Task/Y-combinator/Chapel/y-combinator-2.chpl
Normal file
48
Task/Y-combinator/Chapel/y-combinator-2.chpl
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
// this is the longer version...
|
||||
/*
|
||||
proc fixy(f) {
|
||||
record InnerFunc {
|
||||
const xi;
|
||||
proc this() { return xi(xi); }
|
||||
}
|
||||
record XFunc {
|
||||
const fi;
|
||||
proc this(x) { return fi(new InnerFunc(x)); }
|
||||
}
|
||||
const g = new XFunc(f);
|
||||
return g(g);
|
||||
}
|
||||
// */
|
||||
|
||||
// short version using direct recursion as Chapel has...
|
||||
// note that this version of fix uses function recursion in its own definition;
|
||||
// thus its use just means that the recursion has been "pulled" into the "fix" function,
|
||||
// instead of the function that uses it...
|
||||
proc fixy(f) {
|
||||
record InnerFunc { const fi; proc this() { return fixy(fi); } }
|
||||
return f(new InnerFunc(f));
|
||||
}
|
||||
|
||||
record Facy {
|
||||
record FacFunc {
|
||||
const fi;
|
||||
proc this(n: int): int {
|
||||
return if n <= 1 then 1 else n * fi()(n - 1); }
|
||||
}
|
||||
proc this(f) { return new FacFunc(f); }
|
||||
}
|
||||
|
||||
record Fiby {
|
||||
record FibFunc {
|
||||
const fi;
|
||||
proc this(n: int): int {
|
||||
return if n <= 1 then n else fi()(n - 2) + fi()(n - 1); }
|
||||
}
|
||||
proc this(f) { return new FibFunc(f); }
|
||||
}
|
||||
|
||||
const facy = fixy(new Facy());
|
||||
const fibz = fixy(new Fiby());
|
||||
|
||||
writeln(facy(10));
|
||||
writeln(fibz(10));
|
||||
51
Task/Y-combinator/PowerShell/y-combinator-1.ps1
Normal file
51
Task/Y-combinator/PowerShell/y-combinator-1.ps1
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
$fac = {
|
||||
param([ScriptBlock] $f)
|
||||
invoke-expression @"
|
||||
{
|
||||
param([int] `$n)
|
||||
if (`$n -le 0) {1}
|
||||
else {`$n * {$f}.InvokeReturnAsIs(`$n - 1)}
|
||||
}
|
||||
"@
|
||||
}
|
||||
|
||||
$fib = {
|
||||
param([ScriptBlock] $f)
|
||||
invoke-expression @"
|
||||
{
|
||||
param([int] `$n)
|
||||
switch (`$n)
|
||||
{
|
||||
0 {1}
|
||||
1 {1}
|
||||
default {{$f}.InvokeReturnAsIs(`$n-1)+{$f}.InvokeReturnAsIs(`$n-2)}
|
||||
}
|
||||
}
|
||||
"@
|
||||
}
|
||||
|
||||
$Z = {
|
||||
param([ScriptBlock] $f)
|
||||
invoke-expression @"
|
||||
{
|
||||
param([ScriptBlock] `$x)
|
||||
{$f}.InvokeReturnAsIs(`$(invoke-expression @`"
|
||||
{
|
||||
param(```$y)
|
||||
{`$x}.InvokeReturnAsIs({`$x}).InvokeReturnAsIs(```$y)
|
||||
}
|
||||
`"@))
|
||||
}.InvokeReturnAsIs({
|
||||
param([ScriptBlock] `$x)
|
||||
{$f}.InvokeReturnAsIs(`$(invoke-expression @`"
|
||||
{
|
||||
param(```$y)
|
||||
{`$x}.InvokeReturnAsIs({`$x}).InvokeReturnAsIs(```$y)
|
||||
}
|
||||
`"@))
|
||||
})
|
||||
"@
|
||||
}
|
||||
|
||||
$Z.InvokeReturnAsIs($fac).InvokeReturnAsIs(5)
|
||||
$Z.InvokeReturnAsIs($fib).InvokeReturnAsIs(5)
|
||||
48
Task/Y-combinator/PowerShell/y-combinator-2.ps1
Normal file
48
Task/Y-combinator/PowerShell/y-combinator-2.ps1
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
$Y = {
|
||||
param ($f)
|
||||
|
||||
{
|
||||
param ($x)
|
||||
|
||||
$f.InvokeReturnAsIs({
|
||||
param ($y)
|
||||
|
||||
$x.InvokeReturnAsIs($x).InvokeReturnAsIs($y)
|
||||
}.GetNewClosure())
|
||||
|
||||
}.InvokeReturnAsIs({
|
||||
param ($x)
|
||||
|
||||
$f.InvokeReturnAsIs({
|
||||
param ($y)
|
||||
|
||||
$x.InvokeReturnAsIs($x).InvokeReturnAsIs($y)
|
||||
}.GetNewClosure())
|
||||
|
||||
}.GetNewClosure())
|
||||
}
|
||||
|
||||
$fact = {
|
||||
param ($f)
|
||||
|
||||
{
|
||||
param ($n)
|
||||
|
||||
if ($n -eq 0) { 1 } else { $n * $f.InvokeReturnAsIs($n - 1) }
|
||||
|
||||
}.GetNewClosure()
|
||||
}
|
||||
|
||||
$fib = {
|
||||
param ($f)
|
||||
|
||||
{
|
||||
param ($n)
|
||||
|
||||
if ($n -lt 2) { 1 } else { $f.InvokeReturnAsIs($n - 1) + $f.InvokeReturnAsIs($n - 2) }
|
||||
|
||||
}.GetNewClosure()
|
||||
}
|
||||
|
||||
$Y.invoke($fact).invoke(5)
|
||||
$Y.invoke($fib).invoke(5)
|
||||
1
Task/Y-combinator/Rebol/y-combinator-1.rebol
Normal file
1
Task/Y-combinator/Rebol/y-combinator-1.rebol
Normal file
|
|
@ -0,0 +1 @@
|
|||
Y: closure [g] [do func [f] [f :f] closure [f] [g func [x] [do f :f :x]]]
|
||||
2
Task/Y-combinator/Rebol/y-combinator-2.rebol
Normal file
2
Task/Y-combinator/Rebol/y-combinator-2.rebol
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fact*: closure [h] [func [n] [either n <= 1 [1] [n * h n - 1]]]
|
||||
fact: Y :fact*
|
||||
18
Task/Y-combinator/Rhombus/y-combinator-1.rhombus
Normal file
18
Task/Y-combinator/Rhombus/y-combinator-1.rhombus
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#lang rhombus
|
||||
|
||||
fun Y(f):
|
||||
fun g(h):
|
||||
f(fun(x): h(h)(x))
|
||||
g(g)
|
||||
|
||||
fun fact(f):
|
||||
fun(n):
|
||||
if (n == 0)
|
||||
| 1
|
||||
| n * f(n - 1)
|
||||
|
||||
fun fib(f):
|
||||
fun(n):
|
||||
if (n <= 1)
|
||||
| n
|
||||
| f(n - 1) + f(n - 2)
|
||||
3
Task/Y-combinator/Rhombus/y-combinator-2.rhombus
Normal file
3
Task/Y-combinator/Rhombus/y-combinator-2.rhombus
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fun Y(f):
|
||||
fun g(h): f(h(h)(_))
|
||||
g(g)
|
||||
Loading…
Add table
Add a link
Reference in a new issue