about summary refs log tree commit diff stats
path: root/type.lua
diff options
context:
space:
mode:
Diffstat (limited to 'type.lua')
-rw-r--r--type.lua14
1 files changed, 14 insertions, 0 deletions
diff --git a/type.lua b/type.lua index 3c26188..07f78f1 100644 --- a/type.lua +++ b/type.lua
@@ -97,6 +97,20 @@ function m.cons (a, b)
97 end 97 end
98 return "(" .. table.concat(out, " ") .. ")" 98 return "(" .. table.concat(out, " ") .. ")"
99 end, 99 end,
100 __len =
101 function (self)
102 local function go (lis, acc)
103 -- improper lists don't have lengths
104 -- ... but don't error here.
105 if not m.isa(lis, "cons") then
106 return nil
107 end
108 if lis[2] == m.null then return acc
109 else return go(lis[2], acc+1)
110 end
111 end
112 return go(self, 1)
113 end,
100 } 114 }
101 return setmetatable(t, mt) 115 return setmetatable(t, mt)
102end 116end