diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/fib.rhope	Tue Apr 28 23:06:07 2009 +0000
@@ -0,0 +1,30 @@
+/*
+	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]]
+}