Last active
August 29, 2015 14:04
-
-
Save twfarland/f030cb2853cdf28b25ed to your computer and use it in GitHub Desktop.
Syntax style ideas for a statically-typed lisp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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