Anonymous recursion: Difference between revisions
Content deleted Content added
No edit summary |
|||
Line 640: | Line 640: | ||
=={{header|Elena}}== |
=={{header|Elena}}== |
||
ELENA |
ELENA 4.0: |
||
<lang elena> |
<lang elena>/// Anonymous recursion |
||
import extensions; |
|||
fib(n) |
fib(n) |
||
{ |
|||
[ |
|||
if (n < 0) |
if (n < 0) |
||
{ InvalidArgumentException.raise() }; |
|||
^ ( |
^ (n) |
||
{ |
|||
if (n > 1) |
if (n > 1) |
||
{ |
|||
^ this self(n - 2) + (this self(n - 1)) |
|||
⚫ | |||
⚫ | |||
] |
|||
⚫ | |||
{ |
|||
^ n |
|||
} |
|||
⚫ | |||
} |
|||
public program |
public program() |
||
{ |
|||
[ |
|||
-1 |
for (int i := -1, i <= 10, i += 1) |
||
{ |
|||
console.print("fib(",i,")="); |
|||
try |
|||
{ |
|||
⚫ | |||
} |
|||
catch(Exception e) |
|||
{ |
{ |
||
console.printLine:"invalid" |
|||
⚫ | |||
⚫ | |||
⚫ | |||
} |
} |
||
}; |
|||
console |
console.readChar() |
||
}</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |