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
# Demo that for calls each | |
class ThreeOf | |
def initialize(value) | |
@value = value | |
end | |
def each(&block) | |
block.call(@value) | |
block.call(@value) |
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
require 'oj' | |
require 'stringio' | |
require 'json' | |
class Handler | |
def hash_start | |
{} | |
end | |
def hash_set(h,k,v) |
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
(defn repl [env] | |
(let [dictionary (:dictionary env)] | |
(if (:quit env) | |
env | |
(let [r (:in env) | |
compiled (comp/compile-statement r dictionary)] | |
(if (and (coll? compiled) (empty? compiled)) | |
env | |
(let [result (exec/execute-program env compiled) ;; Get the lazy sequence of states | |
new-env (last result)] ;; ... and then the last one |
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
require 'lithp' | |
require 'lisp_parser' | |
lisp = Lisp.new | |
print "> " | |
while not $stdin.eof? | |
line = readline | |
s_expression = SExpressionParser.new(line).parse | |
p lisp.eval(s_expression) |
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
class SExpressionParser | |
def initialize(expression) | |
@tokens = expression.scan /[()]|\w+|".*?"|'.*?'/ | |
end | |
def peek | |
@tokens.first | |
end | |
def next_token |