NatStructure.borg
NatStructure.borg
{
If():: if(if(true,false,true),false,if(true,true));
Case()::
{
a<>b:[a,b];
c:case(1 <> 99, 2 <> 98, 3 <> 97, 10 <> 90);
if (c(1) = 99,
if (c(2) = 98,
if (c(3) = 97,
if (c(10) = 90, true,
false),
false),
false),
false)
};
Recurse()::
{
fib(n,f1,f2)::
{
if (n > 1,
{
f1:=fib(n-1,f1,f2);
f2:=fib(n-2,f1,f2);
n:=f1+f2;
n
},
1)
};
fib(12,0,0)=233
};
TailRecurse()::
{
n:m:void;
CreateFrames(n)::
if (n=0,
{
gc();
m:=m-freemem()
},
CreateFrames(n-1));
` wait 1-2 seconds
t:time();
u:t[1]+t[2]*60+2;
while({t:=time(); t[1]+t[2]*60}true);
` continue, everything should be printed by now
gc();
m:=freemem();
CreateFrames(100);
n:=m;
gc();
m:=freemem();
CreateFrames(200);
` display(text(n)+"/"+text(m));
m=n
};
ITEM("if",If,1);
ITEM("case",Case,1);
ITEM("recursion",Recurse,100);
ITEM("tailrecursion",TailRecurse,10000)
}