From d8bc4b0236cc09ac45323bffcd740388aab57e1d Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 16 Apr 2024 22:28:51 -0500 Subject: Fix a subtle bug in adding parameters to local procedure envs I couldn't use e[p[1]] = r[1] because that invokes environment's __newindex metamethod, which is equivalent to `set!' -- that is, it mutates the existing binding from the closest enclosing environment --- type.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/type.lua b/type.lua index e4fccc9..e2370b6 100644 --- a/type.lua +++ b/type.lua @@ -299,8 +299,7 @@ function m.procedure (params, body, env, eval) end -- (lambda x ..) or (lambda (x . y) ..) if type.isp(p, "symbol") then - e[p] = r - return e + return rawset(e, p, r) end if p[1] == nil then error("too many arguments", @@ -311,7 +310,7 @@ function m.procedure (params, body, env, eval) rlen, #self.params) end -- bind car(p) to car(r) - e[p[1]] = r[1] + rawset(e, p[1], r[1]) -- recurse return doargs(p[2], r[2], e) end -- cgit 1.4.1-21-gabe81