Examples
These scripts are also in
examples/
and can be run with
lupe run
.
Hello
Fibonacci
examples/fibonacci.lupe
builds the first ten Fibonacci numbers. The constant is the length of the list. The function keeps two running values and appends the current one on each pass.
const LIMIT = 10
function fibonacci(count)
let result = []
let a = 0
let b = 1
for i = 1 to count
append(result, a)
let next_value = a + b
a = b
b = next_value
end
return result
end
print "Lupe Fibonacci Generator"
print "------------------------"
let numbers = fibonacci(LIMIT)
for number in numbers
print number
end
The printed sequence is
0
,
1
,
1
,
2
,
3
,
5
,
8
,
13
,
21
,
34
.
A Module
examples/maths.lupe
:
examples/use_maths.lupe
loads it from the same directory:
That prints
52
.