Skip to content

Latest commit

 

History

History
76 lines (56 loc) · 984 Bytes

brouwer.md

File metadata and controls

76 lines (56 loc) · 984 Bytes

brouwer (a scripting language)

hello, world!

print "hello, world!"

factorial

fn fac n
    case n
        0 => 1
        x => x * fac(n - 1)

-- or

fn fac2 n
    if n < 2
        1
    else
        n * fac2(n - 1)

n = read input
print (fac n)

More advanced version, exception handling and better typing:

fn fac (n: Nat) -> Nat
    case n
        0 => 1
        x => x * fac(x - 1)

try
    n = read input
    print (fac n)
catch err
    print err

calculator

import Char (isDigit)


task calculator
    put "==> "
    var inp = input

    tokens = []
    var num = ""
    while length input > 0
        if isDigit input[0]
            num :> input[0]
        else
            if length num > 0
                tokens :> num
            tokens :> ("" :> input[0])

        input = input[1;]
    if length num > 0
        tokens :>


calculator

water tower problem

where xs :> x xs.push(x)