Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tentative file extension for crono lisp

  • Loading branch information...
commit bc2607fd1b73c386ef9e6d0f7e442aa995255b27 1 parent 4ff2448
Mark Watts authored
Showing with 60 additions and 0 deletions.
  1. +60 −0 crono/prelude.crisp
View
60 crono/prelude.crisp
@@ -0,0 +1,60 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% boolean functions
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+(define not (\ (bool) (if (= bool nil) #t #f)))
+
+(define and (\ (a b) (if a b nil)))
+
+(define or (\ (a b) (if a t b)))
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% higher order functions
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+(define map (\ (f l) (if (= l nil) nil (cons (f (car l)) (map f (cdr l))))))
+
+(define _foldl (\ (f l s) (if (= l nil) s (_foldl f (cdr l) (f s (car l))))))
+
+(define foldl (\ (f l) (if (= l nil) nil (_foldl f (cdr l) (car l)))))
+
+(define _foldr (\ (f l s) (if (= l nil) s (f (car l) (_foldr f (cdr l) s)))))
+
+(define foldr (\ (f l) (if (= l nil) nil (_foldr f (cdr l) (car l)))))
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% math functions
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+(define ! (\ (n) (if (= n 0) 1 (* (! (- n 1)) n))))
+
+(define mod (\ (x y) (if (< x y) x (mod (- x y) y))))
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% combinators
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%identity combinator
+(define <I> (\ (x) x))
+
+%Constant combinator
+(define <K> (\ (x y) x))
+
+%General application combinator
+(define <S> (\ (f g x) (f x (g x))))
+
+%Function composition combinator
+(define <B> (\ (f g x) (f (g x))))
+
+%
+(define <C> (\ (f x y) (f y x)))
+
+%(define <Y> (f)
+% (f (<Y> f)) )
+%Cannata's incorrect definition of Y combinator
+
+%Recursive function
+(define <Z> (\ (f)
+ ((\ (x) (f (\ (v) ((x x) v))))
+ (\ (x) (f (\ (v) ((x x) v)))))))
+
+(define <Y> (\ (f)
+ (\ (x) (f (x x))) (\ (x) (f (x x))) ))
+
+(define <COND> (\ (p f g x) (if (p x) (f x) (g x))))
Please sign in to comment.
Something went wrong with that request. Please try again.