Created
December 11, 2023 15:31
-
-
Save Glorp/6b00f4e2a1130d7d64f622d6394d0aa8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local Cons = { | |
__tostring = function(cons) return "(" .. tostring(cons.car) .. " . " .. tostring(cons.cdr) .. ")" end | |
} | |
local function cons(car, cdr) | |
local res = { car = car, cdr = cdr } | |
setmetatable(res, Cons) | |
return res | |
end | |
local function list(a, ...) | |
if a == nil then return nil end | |
return cons(a, list(...)) | |
end | |
local function map(f, l) | |
if l == nil then return nil | |
else return cons(f(l.car), map(f, l.cdr)) end | |
end | |
return { | |
cons = cons, | |
list = list, | |
map = map | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment