diff options
Diffstat (limited to 'ruby')
| -rw-r--r-- | ruby/step0_repl.rb | 1 | ||||
| -rw-r--r-- | ruby/step1_read_print.rb | 4 | ||||
| -rw-r--r-- | ruby/step2_eval.rb | 1 | ||||
| -rw-r--r-- | ruby/step3_env.rb | 1 | ||||
| -rw-r--r-- | ruby/step4_if_fn_do.rb | 2 | ||||
| -rw-r--r-- | ruby/step5_tco.rb | 2 | ||||
| -rw-r--r-- | ruby/step6_file.rb | 7 | ||||
| -rw-r--r-- | ruby/step7_quote.rb | 7 | ||||
| -rw-r--r-- | ruby/step8_macros.rb | 7 | ||||
| -rw-r--r-- | ruby/step9_interop.rb | 7 | ||||
| -rw-r--r-- | ruby/stepA_more.rb | 8 |
11 files changed, 29 insertions, 18 deletions
diff --git a/ruby/step0_repl.rb b/ruby/step0_repl.rb index 21d534a..9c03cfa 100644 --- a/ruby/step0_repl.rb +++ b/ruby/step0_repl.rb @@ -21,6 +21,7 @@ def REP(str) return PRINT(EVAL(READ(str), {})) end +# repl loop while line = _readline("user> ") puts REP(line) end diff --git a/ruby/step1_read_print.rb b/ruby/step1_read_print.rb index 617323e..ded992a 100644 --- a/ruby/step1_read_print.rb +++ b/ruby/step1_read_print.rb @@ -24,10 +24,12 @@ def REP(str) return PRINT(EVAL(READ(str), {})) end +# repl loop while line = _readline("user> ") begin puts REP(line) rescue Exception => e - puts "Error: %{e}" + puts "Error: #{e}" + puts "\t#{e.backtrace.join("\n\t")}" end end diff --git a/ruby/step2_eval.rb b/ruby/step2_eval.rb index 1454d8c..50a135d 100644 --- a/ruby/step2_eval.rb +++ b/ruby/step2_eval.rb @@ -55,6 +55,7 @@ repl_env[:-] = lambda {|a,b| a - b} repl_env[:*] = lambda {|a,b| a * b} repl_env[:/] = lambda {|a,b| a / b} +# repl loop while line = _readline("user> ") begin puts REP[line] diff --git a/ruby/step3_env.rb b/ruby/step3_env.rb index 88811f0..17126c5 100644 --- a/ruby/step3_env.rb +++ b/ruby/step3_env.rb @@ -67,6 +67,7 @@ repl_env.set(:-, lambda {|a,b| a - b}) repl_env.set(:*, lambda {|a,b| a * b}) repl_env.set(:/, lambda {|a,b| a / b}) +# repl loop while line = _readline("user> ") begin puts REP[line] diff --git a/ruby/step4_if_fn_do.rb b/ruby/step4_if_fn_do.rb index 4ae0d86..a93463b 100644 --- a/ruby/step4_if_fn_do.rb +++ b/ruby/step4_if_fn_do.rb @@ -81,11 +81,11 @@ REP = lambda {|str| PRINT(EVAL(READ(str), repl_env)) } # core.rb: defined using ruby $core_ns.each do |k,v| repl_env.set(k,v) end -repl_env.set(:eval, lambda {|ast| EVAL(ast, repl_env)}) # core.mal: defined using the language itself RE["(def! not (fn* (a) (if a false true)))"] +# repl loop while line = _readline("user> ") begin puts REP[line] diff --git a/ruby/step5_tco.rb b/ruby/step5_tco.rb index e2fe5e7..6be04ae 100644 --- a/ruby/step5_tco.rb +++ b/ruby/step5_tco.rb @@ -90,11 +90,11 @@ REP = lambda {|str| PRINT(EVAL(READ(str), repl_env)) } # core.rb: defined using ruby $core_ns.each do |k,v| repl_env.set(k,v) end -repl_env.set(:eval, lambda {|ast| EVAL(ast, repl_env)}) # core.mal: defined using the language itself RE["(def! not (fn* (a) (if a false true)))"] +# repl loop while line = _readline("user> ") begin puts REP[line] diff --git a/ruby/step6_file.rb b/ruby/step6_file.rb index 45de088..191febe 100644 --- a/ruby/step6_file.rb +++ b/ruby/step6_file.rb @@ -91,17 +91,18 @@ REP = lambda {|str| PRINT(EVAL(READ(str), repl_env)) } # core.rb: defined using ruby $core_ns.each do |k,v| repl_env.set(k,v) end repl_env.set(:eval, lambda {|ast| EVAL(ast, repl_env)}) +repl_env.set(:"*ARGV*", List.new(ARGV.slice(1,ARGV.length) || [])) # core.mal: defined using the language itself RE["(def! not (fn* (a) (if a false true)))"] RE["(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"] if ARGV.size > 0 - ARGV.each {|f| - RE["(load-file \"" + f + "\")"] - } + RE["(load-file \"" + ARGV[0] + "\")"] exit 0 end + +# repl loop while line = _readline("user> ") begin puts REP[line] diff --git a/ruby/step7_quote.rb b/ruby/step7_quote.rb index e91058b..18b7db3 100644 --- a/ruby/step7_quote.rb +++ b/ruby/step7_quote.rb @@ -111,17 +111,18 @@ REP = lambda {|str| PRINT(EVAL(READ(str), repl_env)) } # core.rb: defined using ruby $core_ns.each do |k,v| repl_env.set(k,v) end repl_env.set(:eval, lambda {|ast| EVAL(ast, repl_env)}) +repl_env.set(:"*ARGV*", List.new(ARGV.slice(1,ARGV.length) || [])) # core.mal: defined using the language itself RE["(def! not (fn* (a) (if a false true)))"] RE["(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"] if ARGV.size > 0 - ARGV.each {|f| - RE["(load-file \"" + f + "\")"] - } + RE["(load-file \"" + ARGV[0] + "\")"] exit 0 end + +# repl loop while line = _readline("user> ") begin puts REP[line] diff --git a/ruby/step8_macros.rb b/ruby/step8_macros.rb index dd02c4f..3c99cce 100644 --- a/ruby/step8_macros.rb +++ b/ruby/step8_macros.rb @@ -136,6 +136,7 @@ REP = lambda {|str| PRINT(EVAL(READ(str), repl_env)) } # core.rb: defined using ruby $core_ns.each do |k,v| repl_env.set(k,v) end repl_env.set(:eval, lambda {|ast| EVAL(ast, repl_env)}) +repl_env.set(:"*ARGV*", List.new(ARGV.slice(1,ARGV.length) || [])) # core.mal: defined using the language itself RE["(def! not (fn* (a) (if a false true)))"] @@ -144,11 +145,11 @@ RE["(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> RE["(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))"] if ARGV.size > 0 - ARGV.each {|f| - RE["(load-file \"" + f + "\")"] - } + RE["(load-file \"" + ARGV[0] + "\")"] exit 0 end + +# repl loop while line = _readline("user> ") begin puts REP[line] diff --git a/ruby/step9_interop.rb b/ruby/step9_interop.rb index 2c56de4..507114e 100644 --- a/ruby/step9_interop.rb +++ b/ruby/step9_interop.rb @@ -138,6 +138,7 @@ REP = lambda {|str| PRINT(EVAL(READ(str), repl_env)) } # core.rb: defined using ruby $core_ns.each do |k,v| repl_env.set(k,v) end repl_env.set(:eval, lambda {|ast| EVAL(ast, repl_env)}) +repl_env.set(:"*ARGV*", List.new(ARGV.slice(1,ARGV.length) || [])) # core.mal: defined using the language itself RE["(def! not (fn* (a) (if a false true)))"] @@ -146,11 +147,11 @@ RE["(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> RE["(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))"] if ARGV.size > 0 - ARGV.each {|f| - RE["(load-file \"" + f + "\")"] - } + RE["(load-file \"" + ARGV[0] + "\")"] exit 0 end + +# repl loop while line = _readline("user> ") begin puts REP[line] diff --git a/ruby/stepA_more.rb b/ruby/stepA_more.rb index 697caa3..101dee3 100644 --- a/ruby/stepA_more.rb +++ b/ruby/stepA_more.rb @@ -153,6 +153,7 @@ REP = lambda {|str| PRINT(EVAL(READ(str), repl_env)) } # core.rb: defined using ruby $core_ns.each do |k,v| repl_env.set(k,v) end repl_env.set(:eval, lambda {|ast| EVAL(ast, repl_env)}) +repl_env.set(:"*ARGV*", List.new(ARGV.slice(1,ARGV.length) || [])) # core.mal: defined using the language itself RE["(def! *host-language* \"ruby\")"] @@ -162,11 +163,12 @@ RE["(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> RE["(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))"] if ARGV.size > 0 - ARGV.each {|f| - RE["(load-file \"" + f + "\")"] - } + RE["(load-file \"" + ARGV[0] + "\")"] exit 0 end + +# repl loop +RE["(println (str \"Mal [\" *host-language* \"]\"))"] while line = _readline("user> ") begin puts REP[line] |
