Jump to content

Anonymous recursion: Difference between revisions

Add Axiom task
(Added simple D entry)
(Add Axiom task)
Line 52:
{ return n < 0 ? "error" : n < 2 ? 1 : n * fib(n-1)
}</lang>
=={{header|Axiom}}==
Axiom currently has scope issues with calling a local function recursively. One solution is
to use the Reference (pointer) domain and initialise the local function with a dummy value:
<lang axiom>)abbrev package TESTP TestPackage
Z ==> Integer
TestPackage : with
fib : Z -> Z
== add
fib x ==
x <= 0 => error "argument outside of range"
f : Reference((Z,Z,Z) -> Z) := ref((n, v1, v2) +-> 0)
f() := (n, v1, v2) +-> if n<2 then v2 else f()(n-1,v2,v1+v2)
f()(x,1,1)</lang>
 
=={{header|Bracmat}}==
136

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.