example.gisp 635 B

123456789101112131415161718192021222324252627282930313233343536
  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. x)
  7. (defn not (x)
  8. (if x #f #t))
  9. (defn false? (x)
  10. (not (true? x)))
  11. (defn zero? (x)
  12. (if (== x 0) #t (== x 0.0)))
  13. (defn apply (fn xs)
  14. (eval `(,fn ,@xs)))
  15. (defn inc (x)
  16. (+ x 1))
  17. (defn dec
  18. (x) (- x 1))
  19. (defmacro unless (condition & body)
  20. `(if (not ,condition) (begin ,@body)))
  21. (defmacro fn (a b c & rest)
  22. (let ((x (inc a)) (y (dec b)))
  23. `(if (== ,x ,y)
  24. ,c
  25. (begin ,@rest))))