about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2024-04-10 23:41:12 -0500
committerCase Duckworth2024-04-10 23:41:12 -0500
commit8aae1d44e498ac9170e2b520fe9384d1ebb8b3c1 (patch)
treef1e473f77855a8b7211fcedd648a76c22bb81628
parentFix typo (diff)
downloadlam-8aae1d44e498ac9170e2b520fe9384d1ebb8b3c1.tar.gz
lam-8aae1d44e498ac9170e2b520fe9384d1ebb8b3c1.zip
Add assert_type, string value keys; fix typo
-rw-r--r--type.lua11
1 files changed, 10 insertions, 1 deletions
diff --git a/type.lua b/type.lua index 0000bfb..cf24d0c 100644 --- a/type.lua +++ b/type.lua
@@ -217,6 +217,7 @@ function m.string (x)
217 else 217 else
218 t = tochars(tostring(x)) 218 t = tochars(tostring(x))
219 end 219 end
220 t.v = table.concat(t)
220 local mt = { 221 local mt = {
221 __type = "string", 222 __type = "string",
222 __tostring = 223 __tostring =
@@ -263,6 +264,13 @@ function m.listp (x)
263 end 264 end
264end 265end
265 266
267-- type assertion
268function m.assert_type (x, t)
269 if not m.isp(x, t) then
270 error("wrong type", m.lamtype(x), t)
271 end
272end
273
266-- according to CHICKEN, `atom?' returns #t if X is not a pair (cons) 274-- according to CHICKEN, `atom?' returns #t if X is not a pair (cons)
267function m.atomp (x) 275function m.atomp (x)
268 return not m.isp(x, "pair") 276 return not m.isp(x, "pair")
@@ -276,10 +284,11 @@ function m.totable (cons)
276 local t, p = {}, cons 284 local t, p = {}, cons
277 while p[2] do 285 while p[2] do
278 table.insert(t, p[1]) 286 table.insert(t, p[1])
279 if m.isp(p[2]) == "pair" then 287 if m.isp(p[2], "pair") then
280 p = p[2] 288 p = p[2]
281 else 289 else
282 table.insert(t, p[2]) 290 table.insert(t, p[2])
291 break
283 end 292 end
284 end 293 end
285 return t 294 return t