view fib.rhope @ 189:d0e3a13c1bd9 default tip

Remove old calculator example
author Mike Pavone <pavone@retrodev.com>
date Fri, 07 Oct 2011 00:24:04 -0700
parents a163250b8885
children
line wrap: on
line source

/*
	This example program contains a naive implementation of the Fibonacci function
	While this isn't a particular fast way to implement the Fibonacci function it does parallize nicely
*/


//Here we define a worker Fib with one input named 'n' and one output named 'out'
Fib[n:out]
{
	//The If worker is one way to conditionally execute a piece of code
	If[[n] < [2]]
	{
		//This line will execute if [n] < [2] evaluates to Yes
		out <- 1	
	}{
		//This line will execute if [n] < [2] evaluates to No
		//All Worker calls can be expressed in infix, postfix, or prefix notation
		//So [n]-[1] is the same as -[n,1] and [n,1]-
		out <- [Fib[[n]-[1]]] + [Fib[[n]-[2]]]
	}
}

Main[args]
{
	//Here we get the first command line argument and convert it to a number
	n <- Int32[[args]Index[1]]
	//Call our Fib worker and Print the result to the terminal
	Print[Fib[n]]
}