prelude.gisp 689 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. (define defn (macro (name params & body)
  2. `(define ,name (lambda ,params ,@body))))
  3. (define defmacro (macro (name params & body)
  4. `(define ,name (macro ,params ,@body))))
  5. (defn id (x)
  6. "This is the identity function, it returns its argument"
  7. x)
  8. (defn not (x)
  9. (if x #f #t))
  10. (defn false? (x)
  11. (not (true? x)))
  12. (defn zero? (x)
  13. (if (== x 0) #t (== x 0.0)))
  14. (defmacro apply (fn xs)
  15. `(,fn ,@,xs))
  16. (defn inc (x)
  17. (+ x 1))
  18. (defn dec (x)
  19. (- x 1))
  20. (println "prelude loaded!")
  21. ; assertions from here on
  22. (assert (not (not #t)))
  23. (assert (not #f))
  24. (assert (zero? 0))
  25. (assert (zero? 0.0))
  26. (assert ((lambda (x) x) #t))
  27. (assert (true? #t))
  28. (assert (false? #f))