Skip to content

Instantly share code, notes, and snippets.

@twfarland
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twfarland/f030cb2853cdf28b25ed to your computer and use it in GitHub Desktop.
Save twfarland/f030cb2853cdf28b25ed to your computer and use it in GitHub Desktop.
Syntax style ideas for a statically-typed lisp
;; A translation of the example on http://nightmare.com/rushing/irken/irken/lang.html
;; Type definition follows Haskell's approach
(data (tree a)
empty
(node a (tree a) (tree a)))
;; Function has type and arity defined after the name
;; patterns against that type are matched after that
(def (indent int bool)
(0 false)
(n (begin (print " ") (indent (- n 1)))))
;; So e.g: whenever 'print' is called with an int and a tree of anything,
;; this is the definition to use:
(def (print int (tree a) bool)
(d empty false)
(d (node val left right) (begin
(indent d)
(print (+ d 1) left)
(print val)
(print "\n")
(print (+ d 1) right))))
(let ((t (tree int))
(node 5
(node 7 empty (node 12 empty empty))
(node 9 empty empty)))
(print 0 t))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment