(define \$integer (matcher { [,\$n [] {[\$tgt (if (eq? tgt n) {[]} {})]}] [\$ [something] {[\$tgt {tgt}]}] })) (define \$compare-integer (lambda [\$m \$n] (if (lt? m n) (if (eq? m n) )))) (define \$float (matcher {[,\$d [] {[\$tgt (if (eq? tgt d) {[]} {})]}] [\$ [something] {[\$tgt {tgt}]}] })) (define \$compare-float (lambda [\$d1 \$d2] (if (lt? d1 d2) (if (eq? d1 d2) )))) (define \$nat (matcher {[,\$n [] {[\$tgt (if (eq? tgt n) {[]} {})]}] [ [] {[0 {[]}] [_ {}]}] [ nat {[\$tgt (match (compare-integer tgt 0) ordering {[ {(- tgt 1)}] [_ {}]})]}] [\$ [something] {[\$tgt {tgt}]}] })) (define \$between (lambda [\$m \$n] (match (compare-integer m n) ordering {[ {m @(between (+ m 1) n)}] [ {n}] [ {}]}))) (define \$from (lambda [\$m] {m @(from (+ m 1))})) (define \$min (lambda [\$ns] (match ns (list integer) {[> n] [ (let {[\$r (min rs)]} (match (compare-integer n r) ordering {[ n] [_ r]}))]}))) (define \$max (lambda [\$ns] (match ns (list integer) {[> n] [ (let {[\$r (max rs)]} (match (compare-integer n r) ordering {[ n] [_ r]}))]}))) (define \$min-and-max (lambda [\$ns] (match ns (list integer) {[> [n n]] [ (let {[[\$min-n \$max-n] (min-and-max rs)]} (match (compare-integer n min-n) ordering {[ [n max-n]] [_ (match (compare-integer n max-n) ordering {[ [min-n n]] [_ [min-n max-n]]})]}))]}))) (define \$gcd (lambda [\$ns] (match ns (set integer) {[> n] [ (gcd {m @((remove-all integer) (map (lambda [\$r] (mod r m)) rs) 0)})]}))) (define \$fib (lambda [\$n] (letrec {[\$fib1 (lambda [\$n \$ret1 \$ret2] (match n nat {[ ret2] [> ret1] [ (fib1 (- n 1) (+ ret1 ret2) ret1)] }))]} (fib1 n 1 1)))) (define \$fact (lambda [\$n] (letrec {[\$fact1 (lambda [\$n \$ret] (match n [nat] {[ ret] [ (fact1 n1 (* n ret))]}))]} (fact1 n 1)))) (define \$mod (lambda [\$m] (matcher {[,\$n [] {[\$tgt (if (eq? (modulo tgt m) (modulo n m)) {[]} {})]}] [\$ [something] {[\$tgt {(modulo tgt m)}]}] }))) (define \$primes (letrec {[\$next-primes (lambda [\$primes1 \$n] (if (one-of (lambda [\$p] (eq-n? (remainder n p) 0)) primes1) (next-primes primes1 (+ n 1)) {n @(next-primes {@primes1 n} (+ n 1))}))]} {2 @(next-primes {2} 3)}))