From bbaff0e0c204c2fab216f6501dc8c11b4425b4bc Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Mon, 4 Mar 2024 21:01:27 -0600 Subject: Ugghhhh totally not working --- eval.lua | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'eval.lua') diff --git a/eval.lua b/eval.lua index 185268f..806148d 100644 --- a/eval.lua +++ b/eval.lua @@ -5,12 +5,14 @@ local read = require "read" local util = require "util" local pp = require "pp" local global = require "global" -local types = require("types") +local types = require "types" +table.unpack = table.unpack or unpack -if not table.unpack then table.unpack = unpack end +--- Environments and Parameters +-- these aren't in types.lua to avoid a circular dependency local function Env(inner, outer) - return setmetatable(inner, { __type = "environment", __index = outer, }) + return setmetatable(inner, { __type = "Environment", __index = outer, }) end local function Proc(params, body, env) @@ -20,7 +22,7 @@ local function Proc(params, body, env) env = env, } local mt = { - __type = "procedure", + __type = "Procedure", __call = function (self, ...) local inner = {} @@ -37,23 +39,23 @@ end function eval.eval (x, e) e = e or global - if types.lamtype(x) == "symbol" then + if types.lamtype(x) == "Symbol" then return e[x] elseif types.luatype(x) ~= "table" then return x else local op = util.car(x) local args = util.cdr(x) - if op == "quote" then + if op == types.Symbol("quote") then return args[1] - elseif op == "define" then + elseif op == types.Symbol("define") then local sym, exp = table.unpack(args) e[sym] = eval(exp, e) --[[ elseif op == "set!" then local sym, exp = table.unpack(args) e[sym] = eval(exp, e) --]] - elseif op == "lambda" then + elseif op == types.Symbol("lambda") then local params = util.car(args) local body = util.cdr(args) table.insert(body, 1, "begin") -- cgit 1.4.1-21-gabe81