lib/lasp/interpreter.rb in lasp-0.10.1 vs lib/lasp/interpreter.rb in lasp-0.11.0

- old
+ new

@@ -1,5 +1,6 @@ +require "lasp" require "lasp/fn" require "lasp/macro" require "lasp/errors" module Lasp @@ -20,16 +21,17 @@ def eval_form(form, env) head, *tail = *form case head - when :def then def_special_form(tail, env) - when :fn then fn_special_form(tail, env) - when :do then do_special_form(tail, env) - when :if then if_special_form(tail, env) - when :quote then quote_special_form(tail, env) - when :macro then macro_special_form(tail, env) + when :def then def_special_form(tail, env) + when :fn then fn_special_form(tail, env) + when :do then do_special_form(tail, env) + when :if then if_special_form(tail, env) + when :quote then quote_special_form(tail, env) + when :macro then macro_special_form(tail, env) + when :require then require_special_form(tail, env) else call_function(head, tail, env) end end def resolve_symbol(symbol, env) @@ -72,8 +74,17 @@ end def macro_special_form(form, env) params, func = form Macro.new(params, func, env) + end + + def require_special_form(form, env) + require_path, is_relative = form + + require_root = is_relative ? File.dirname(env.fetch(:__FILE__)) : Dir.pwd + absolute_path = File.expand_path(require_path, require_root) + + Lasp::execute_file(absolute_path, env) end end end