最后活跃于 18 hours ago

修订 febe08670636a11928f612c4f76f9682b2c69f06

stuff.lua 原始文件 Playground
1-- quotation.lua
2local function quotation_call(quote, env)
3 if rawget(quote, "namespace") then env.namespace:push(quote.namespace) end
4 for _, item in ipairs(quote.body) do
5 local typ = type(item)
6 if typ == "number" or typ == "boolean" or typ == "string" or (typ == "table" and item.type == "quote") then
7 env.data:push(item)
8 else
9 item(env)
10 end
11 end
12 if rawget(quote, "namespace") then env.namespace:pop() end
13end
14
15-- gilded.lua
16builtins["call"] = function(env)
17 env:assertHeight(1)
18 local quote = env.data:pop()
19 return quote(env)
20end
21
22-- snipped --
23
24local env = enviroment.new()
25for _, item in ipairs(program) do
26 local typ = type(item)
27 if typ == "number" or typ == "boolean" or typ == "string" or (typ == "table" and item.type == "quote") then
28 env.data:push(item)
29 else
30 item(env)
31 end
32end