diff options
-rw-r--r-- | type.lua | 11 |
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 |
264 | end | 265 | end |
265 | 266 | ||
267 | -- type assertion | ||
268 | function m.assert_type (x, t) | ||
269 | if not m.isp(x, t) then | ||
270 | error("wrong type", m.lamtype(x), t) | ||
271 | end | ||
272 | end | ||
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) |
267 | function m.atomp (x) | 275 | function 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 |