Skip to content

Examples

These scripts are also in examples/ and can be run with lupe run .

Hello

#!/usr/bin/env lupe

let name = input("Enter your name: ")
print "Hello, " + name

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 :

function add(a, b)
    return a + b
end

const ANSWER = 42

examples/use_maths.lupe loads it from the same directory:

import "maths.lupe"

print maths.add(10, maths.ANSWER)
lupe run examples/use_maths.lupe

That prints 52 .