Futz with sandbox
This commit is contained in:
parent
fd2a004627
commit
7f0415954c
64
sandbox.ld
64
sandbox.ld
|
@ -1,4 +1,42 @@
|
|||
fn fib {
|
||||
"Tells you a fib number."
|
||||
(0) -> 0
|
||||
(1) -> 1
|
||||
(n) -> add (
|
||||
fib (dec (n))
|
||||
fib (sub (n, 2))
|
||||
)
|
||||
}
|
||||
|
||||
fn unwrap {
|
||||
((:some, value)) -> value
|
||||
((:ok, value)) -> value
|
||||
}
|
||||
|
||||
fn default (default_value) -> fn (maybe) -> when maybe is {
|
||||
(:ok, value) -> value
|
||||
(:err, _) -> default_value
|
||||
nil -> default_value
|
||||
value -> value
|
||||
}
|
||||
|
||||
fn some (value) -> (:some, value)
|
||||
|
||||
fn ok (value) -> (:ok, value)
|
||||
|
||||
let foo = unwrap ((:ok, 42))
|
||||
|
||||
print (:foo, foo)
|
||||
|
||||
let bar = unwrap ((:some, 23))
|
||||
|
||||
print (:bar, bar)
|
||||
|
||||
let baz = do 69 > default (12) > print (:baz, _)
|
||||
|
||||
let quux = do nil > default (12) > print (:quux, _)
|
||||
|
||||
& unwrap ((:err, "message"))
|
||||
|
||||
fn map {
|
||||
(f) -> fn mapper (xs) -> map (f, xs)
|
||||
|
@ -6,7 +44,9 @@ fn map {
|
|||
let n = count (xs)
|
||||
loop (0, []) with (i, ys) -> if eq (i, n)
|
||||
then ys
|
||||
else recur (inc (i), conj (ys, f (nth (i, xs))))
|
||||
else recur (
|
||||
inc (i)
|
||||
conj (ys, f (nth (i, xs))))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,10 +84,28 @@ fn filter {
|
|||
}
|
||||
}
|
||||
|
||||
let greater_than_two = gt (_, 2)
|
||||
& fn shuffle
|
||||
|
||||
ref x = 4
|
||||
|
||||
set! (x, "foo")
|
||||
|
||||
set! (x, :foo)
|
||||
|
||||
deref (x)
|
||||
|
||||
let greater_than_two? = gt (_, 2)
|
||||
|
||||
fn square (x) -> mult (x, x)
|
||||
|
||||
let xs = [1, 2, 3]
|
||||
|
||||
map (square, xs)
|
||||
let ys = #{:a 1, :b 2}
|
||||
|
||||
ys :a
|
||||
|
||||
:a (ys)
|
||||
|
||||
let y = 1
|
||||
|
||||
do y > inc > square > sub (_, 3)
|
||||
|
|
Loading…
Reference in New Issue
Block a user