Mercurial > repos > rhope
comparison fib.rhope @ 0:76568becd6d6
Rhope Alpha 2a source import
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 28 Apr 2009 23:06:07 +0000 |
parents | |
children | a163250b8885 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:76568becd6d6 |
---|---|
1 /* | |
2 This example program contains a naive implementation of the Fibonacci function | |
3 While this isn't a particular fast way to implement the Fibonacci function it does parallize nicely | |
4 */ | |
5 | |
6 | |
7 //Here we define a worker Fib with one input named 'n' and one output named 'out' | |
8 Fib[n:out] | |
9 { | |
10 //The If worker is one way to conditionally execute a piece of code | |
11 If[[n] < [2]] | |
12 { | |
13 //This line will execute if [n] < [2] evaluates to Yes | |
14 out <- 1 | |
15 }{ | |
16 //This line will execute if [n] < [2] evaluates to No | |
17 //All Worker calls can be expressed in infix, postfix, or prefix notation | |
18 //So [n]-[1] is the same as -[n,1] and [n,1]- | |
19 out <- [Fib[[n]-[1]]] + [Fib[[n]-[2]]] | |
20 } | |
21 } | |
22 | |
23 Main[args] | |
24 { | |
25 //Here we get the first command line argument and convert it to a number | |
26 //Yes I realize this is incredibly ugly looking | |
27 n <- <String@Whole Number[[args]Index[1]] | |
28 //Call our Fib worker and Print the result to the terminal | |
29 Print[Fib[n]] | |
30 } |