diff options
| author | Joel Martin <github@martintribe.org> | 2014-04-10 20:34:29 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2014-04-10 20:34:29 -0500 |
| commit | f705f0fce151863091ad77753105f0d15270edec (patch) | |
| tree | 788691596846567abec1606131c972d24211604c /ruby/step1_read_print.rb | |
| parent | 712af9efbe15a9a65c25ab92ee2a49c8e749ed3d (diff) | |
| download | mal-f705f0fce151863091ad77753105f0d15270edec.tar.gz mal-f705f0fce151863091ad77753105f0d15270edec.zip | |
Ruby: step0, step1
Diffstat (limited to 'ruby/step1_read_print.rb')
| -rw-r--r-- | ruby/step1_read_print.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/ruby/step1_read_print.rb b/ruby/step1_read_print.rb new file mode 100644 index 0000000..20dd450 --- /dev/null +++ b/ruby/step1_read_print.rb @@ -0,0 +1,32 @@ +require "readline" +require "types" +require "reader" +require "printer" + +# read +def READ(str) + return read_str(str) +end + +# eval +def EVAL(ast, env) + return ast +end + +# print +def PRINT(exp) + return _pr_str(exp, true) +end + +# repl +def REP(str) + return PRINT(EVAL(READ(str), {})) +end + +while line = Readline.readline("user> ", true) + begin + puts REP(line) + rescue Exception => e + puts "Error: %{e}" + end +end |
