36 lines
649 B
Plaintext
36 lines
649 B
Plaintext
#!/usr/bin/pl
|
|
; Print with newline
|
|
(def prnl (fn (_txt) (
|
|
(prn (cat _txt (ch 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)))
|
|
|
|
; Switch expression
|
|
; Doesn't yet work with lambdas
|
|
;(def switch (fn (val pair_list)
|
|
; (if (= 0 (len pair_list)) "no match"
|
|
; (if (= val (at 0 (at 0 pair_list))) (at 1 (at 0 pair_list)) (
|
|
; (switch val (rest pair_list))
|
|
; ))
|
|
; )
|
|
;))
|