From 8aae1d44e498ac9170e2b520fe9384d1ebb8b3c1 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 10 Apr 2024 23:41:12 -0500 Subject: Add assert_type, string value keys; fix typo --- type.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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) else t = tochars(tostring(x)) end + t.v = table.concat(t) local mt = { __type = "string", __tostring = @@ -263,6 +264,13 @@ function m.listp (x) end end +-- type assertion +function m.assert_type (x, t) + if not m.isp(x, t) then + error("wrong type", m.lamtype(x), t) + end +end + -- according to CHICKEN, `atom?' returns #t if X is not a pair (cons) function m.atomp (x) return not m.isp(x, "pair") @@ -276,10 +284,11 @@ function m.totable (cons) local t, p = {}, cons while p[2] do table.insert(t, p[1]) - if m.isp(p[2]) == "pair" then + if m.isp(p[2], "pair") then p = p[2] else table.insert(t, p[2]) + break end end return t -- cgit 1.4.1-21-gabe81