This sample is a simple benchmark taken & ported from Doug Bagley's Great Language Shootout Pages.
It is an exerciser for recursive method calls, local variable access, and handling of integer numbers. As 'ordinary', small integers are just full-fleshed objects as well in LITTLE, and all operations on them thereby implemented by 'standard' means - methods - the most important VM feature tested here is speed of method lookups.
Usually, LITTLE performs very well in this area.
Concerning source code, this demo includes doc-forms, LITTLE's way of self-documenting code.
To include doc-strings into LITTLE source, you may use the form.
(doc {<string>}*)
The sample uses
(__ {<string>}*)
instead, which is defined as a macro.
(package test)
(using
little.lang.Object
little.io.TextOutputStream)
(class Fib (Object)
(__
"This class is ported from the Great Language Shootout page."
"It measures speed of recursive method calls, local variable"
"access and basic arithmetics.")
(method fib (n):static
(__
"This method recursively computes fibonacci numbers."
"The 'n' argument is expected to be an instance of little.lang.Cardinal")
(cond
((n:lt 1) 0)
((n:equals 1) 1)
(true
((self:fib (n:sub 1)):add (self:fib (n:sub 2))))))
(method main () :static
(__
"The main method invokes (self:fib n), where"
"n is the number passed via (System:arguments)")
(let ((num (((System:arguments):nextElement):toint)))
((TextOutputStream:out):println (self:fib num))))
)