Defining Functions

FerrLisp can define functions, which can be called from inside the script, or from outside the script
(defun, FunctionName, argument variable, argument variable, ..., statement, statement, ...)

(defun Factorial x
	(if (== x 1)
		(1)
		(* x (Factorial (- x 1)))
	)
)

(print (+ '6! = ' (Factorial 6)))

To call a function from within C#, it's as simple as:
ScriptValue factorialResult = functionScript.CallFunction("Factorial", new object[] { 6 });
Console.WriteLine("Call to Factorial(6) = " + factorialResult);

Last edited Apr 10, 2011 at 10:06 PM by koujaku, version 4

Comments

No comments yet.