view fib.rhope @ 75:0083b2f7b3c7

Partially working implementation of List. Modified build scripts to allow use of other compilers. Fixed some bugs involving method implementations on different types returning different numbers of outputs. Added Fold to the 'builtins' in the comipler.
author Mike Pavone <pavone@retrodev.com>
date Tue, 06 Jul 2010 07:52:59 -0400
parents 76568becd6d6
children a163250b8885
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
	//Yes I realize this is incredibly ugly looking
	n <- <String@Whole Number[[args]Index[1]]
	//Call our Fib worker and Print the result to the terminal
	Print[Fib[n]]
}