Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,36 +0,0 @@
|
|||
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));
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
// 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));
|
||||
|
|
@ -6,11 +6,11 @@ singleton YCombinator
|
|||
= (f){(x){ x(x) }((g){ f((x){ (g(g))(x) })})}(func);
|
||||
}
|
||||
|
||||
public program()
|
||||
public Program()
|
||||
{
|
||||
var fib := YCombinator.fix::(f => (i => (i <= 1) ? i : (f(i-1) + f(i-2)) ));
|
||||
var fact := YCombinator.fix::(f => (i => (i == 0) ? 1 : (f(i-1) * i) ));
|
||||
|
||||
console.printLine("fib(10)=",fib(10));
|
||||
console.printLine("fact(10)=",fact(10));
|
||||
Console.printLine("fib(10)=",fib(10));
|
||||
Console.printLine("fact(10)=",fact(10));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,51 +0,0 @@
|
|||
$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)
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
$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 +0,0 @@
|
|||
Y: closure [g] [do func [f] [f :f] closure [f] [g func [x] [do f :f :x]]]
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
fact*: closure [h] [func [n] [either n <= 1 [1] [n * h n - 1]]]
|
||||
fact: Y :fact*
|
||||
Loading…
Add table
Add a link
Reference in a new issue