pebblisp/src/examples/lib.pbl

39 lines
592 B
Plaintext

#!/usr/bin/pl
; Print with newline
(def prnl (fn (_txt) (
(prn _txt)
(pch 10)
)))
; Exponentiate a^b
(def exp (fn (a b)
(if (= b 0)
1
(* a (exp a (- b 1)))
)
))
; Square a
(def sq (fn (a) (* a a)))
; Cube a
(def cube (fn (a) (exp a 3)))
; Return the larger of the two
(def max (fn (a b) (if (> a b) a b)))
; Return the smaller of the two
(def min (fn (a b) (if (< a b) a b)))
(def switch (fn (pair_list)
(if (= 0 (len pair_list))
"no match"
(
(def _pair (at 0 pair_list))
(if (at 0 _pair)
(at 1 _pair)
(switch (rest pair_list))
)
))
))