4377935
Branches > main > 4377935 > files
Only allow simple symbols to be passed to def
Commit: 4377935780dcd28ba0d151b8a36c7cc92c455af9
Parent: 9520b99
1 changed file:
org/faddle/lang/eval.lua view file
@@ -10,6 +10,7 @@ local is_symbol = symbol.is_symbol local intern = symbol.intern local munge = symbol.munge+local module = symbol.module local compiler = require("org.faddle.lang.compile") local compile = compiler.compile@@ -25,7 +26,7 @@ -- So this should add both to a registry of vars, as well as the munged names mapping to the values in the module return table -- And re-defining updates the var and calls its handler or whatever, or calls an update_var() idk, and it also updates the module table local function def(sym, args, env)- assert(is_symbol(sym), "def must be called with a symbol")+ assert(is_symbol(sym) and not module(sym), "def must be called with a simple symbol") assert(modules[env.current_module] ~= nil, "Cannot define var in non-existent module '" .. env.current_module .. "'") local val = eval(first(args), env) -- Doesn't add to the return table right now@@ -36,7 +37,7 @@ return sym end -local function module(mod_name, env)+local function module_form(mod_name, env) if type(mod_name) ~= "string" then error("First argument to module must be a string!") end -- Why not? if package.loaded[mod_name] and not modules[mod_name] then@@ -135,7 +136,7 @@ -- So is this what loads core and alises? local function create_env(mod_name) local env = {current_module = mod_name}- module(mod_name, env)+ module_form(mod_name, env) return env end @@ -144,7 +145,7 @@ if count(form) == 0 then return form end local f = first(form) if f == QUOTE then return second(form) end- if f == MODULE then return module(second(form), env) end+ if f == MODULE then return module_form(second(form), env) end if f == DEF then return def(second(form), rest(rest(form)), env) end if f == FN then return execute(compile(form, true), "eval_fn") end if f == LET then return execute(compile(form, true), "eval_let") end