Skip to content

Instantly share code, notes, and snippets.

@kdridi
Last active December 17, 2018 12:42
Show Gist options
  • Save kdridi/d0d206ed0012b26a2eb3a9e7bad94dda to your computer and use it in GitHub Desktop.
Save kdridi/d0d206ed0012b26a2eb3a9e7bad94dda to your computer and use it in GitHub Desktop.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; read_str
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; (println
; (+ 1 2)
; "Hello, world"
; nil true false)
;
; tokenize => ['(', 'println', '(', '+', '1', '2', ')', '"Hello, world"', 'nil', 'true', 'false', ')']
; read => [ Symbol("println"), [ Symbol("+"), 1, 2 ], "Hello, world", null, true, false ]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; print_ast
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; [ Symbol("println"), [ Symbol("+"), 1, 2 ], "Hello, world", null, true, false ]
; print => (println (+ 1 2) "Hello, world" nil true false)
;>> prints nothing
;>> returns 3
(+ 1 2)
;>> prints
;3
;Hello, "World"
;nil
;true
;false
;>> returns nil
(println
(+ 1 2)
"Hello, \"world\""
nil true false)
;>> prints nothing
;>> returns 100
(def! a 100)
;>> prints
;100
;>> returns nil
(println a)
;>> prints
;42
;>> returns nil
(println (let* (a 10 b (+ 22 a)) (+ a b)))
;>> prints
;100
;>> returns nil
(println a)
;>> prints
;hello
;world
;>> returns 42
(do
(println "hello")
(println "world")
(* 2 3 7))
;>> prints nothing
;>> returns 42
(def! a ((fn* (a b) (* a b)) 6 7))
;>> prints
;42
;>> returns nil
(println a)
;>> prints nothing
;>> returns 'function.toString()'
(def! sum-to
(fn* (n)
(let* (sum-to-aux (fn* (n r)
(if (= n 0)
r
(sum-to-aux (- n 1) (+ r n)))))
(sum-to-aux n 0))))
;>> prints
;50005000
;>> returns nil
(println (sum-to 10000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment