about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2024-04-13 18:02:05 -0500
committerCase Duckworth2024-04-13 18:02:05 -0500
commitfd3db5c3899daaaefba64479cdf73fcf9c8dbdf3 (patch)
tree3b8ac6b0dd8918273785937d7a7a9bcff47f50ba
parentMove port.lua to type.lua (diff)
downloadlam-fd3db5c3899daaaefba64479cdf73fcf9c8dbdf3.tar.gz
lam-fd3db5c3899daaaefba64479cdf73fcf9c8dbdf3.zip
Trim util
-rw-r--r--core.lua8
-rw-r--r--read.lua7
-rw-r--r--type.lua5
-rw-r--r--util.lua13
4 files changed, 10 insertions, 23 deletions
diff --git a/core.lua b/core.lua index 556866c..3e4773a 100644 --- a/core.lua +++ b/core.lua
@@ -2,11 +2,9 @@
2 2
3local dump = require("dump") 3local dump = require("dump")
4local type = require("type") 4local type = require("type")
5local utf8 = require("utf8")
6local null = type.null
7local assert_arity, assert_type = type.assert_arity, type.assert_type 5local assert_arity, assert_type = type.assert_arity, type.assert_type
8local util = require("util") 6local null = type.null
9local error = util.error 7local error = require("util").error
10 8
11local function fold (kons, knil, r) 9local function fold (kons, knil, r)
12 if r == null then 10 if r == null then
@@ -111,7 +109,7 @@ end
111env["integer->char"] = function (r) 109env["integer->char"] = function (r)
112 assert_arity(r,1,1) 110 assert_arity(r,1,1)
113 assert_type(r[1], "number") -- todo: check integer 111 assert_type(r[1], "number") -- todo: check integer
114 return type.character(utf8.char(r[1])) 112 return type.character(r[1])
115end 113end
116 114
117env["string->list"] = function (r) 115env["string->list"] = function (r)
diff --git a/read.lua b/read.lua index 666f509..658ad7d 100644 --- a/read.lua +++ b/read.lua
@@ -4,7 +4,8 @@ local m = {}
4local type = require("type") 4local type = require("type")
5local eof, input_port = type.eof, type.input_port 5local eof, input_port = type.eof, type.input_port
6local util = require("util") 6local util = require("util")
7local constantly, error, pop = util.constantly, util.error, util.pop 7local error, pop = util.error, util.pop
8local utf8_char = require("utf8").char
8 9
9local token_separators = "[%s#()\"'`,@;]" 10local token_separators = "[%s#()\"'`,@;]"
10 11
@@ -127,7 +128,7 @@ local function consume_string_hexvalue (cs)
127 table.insert(u8ch, c) 128 table.insert(u8ch, c)
128 until c == ";" 129 until c == ";"
129 table.remove(u8ch) -- discard ';' 130 table.remove(u8ch) -- discard ';'
130 return utf8.char(tonumber(table.concat(u8ch), 16)), cs 131 return utf8_char(tonumber(table.concat(u8ch), 16)), cs
131end 132end
132 133
133local function consume_string (cs) 134local function consume_string (cs)
@@ -258,7 +259,7 @@ m.readmacros = {
258 table.insert(Q, m.read(port)) 259 table.insert(Q, m.read(port))
259 return type.list(Q) 260 return type.list(Q)
260 end, 261 end,
261 comment = constantly(nil), -- throw comments away 262 comment = function (_,_,_) return nil end,
262} 263}
263 264
264---[[ READ ]]--- 265---[[ READ ]]---
diff --git a/type.lua b/type.lua index 79f42a6..83b29f2 100644 --- a/type.lua +++ b/type.lua
@@ -7,8 +7,9 @@
7 7
8local m = {} 8local m = {}
9local utf8 = require("utf8") 9local utf8 = require("utf8")
10local util = require("util") 10local utf8_char, utf8_codepoint, utf8_codes =
11local tochars, error, constantly = util.tochars, util.error, util.constantly 11 utf8.char, utf8.codepoint, utf8.codes
12local error = require("util").error
12 13
13---[[ ATOMIC TYPES ]]--- 14---[[ ATOMIC TYPES ]]---
14 15
diff --git a/util.lua b/util.lua index a13912c..7040e33 100644 --- a/util.lua +++ b/util.lua
@@ -2,7 +2,6 @@
2 2
3local m = {} 3local m = {}
4local string = string 4local string = string
5local utf8 = require("utf8")
6 5
7m.luaerror = error 6m.luaerror = error
8 7
@@ -23,17 +22,5 @@ function m.pop (tbl)
23 return table.remove(tbl, 1) 22 return table.remove(tbl, 1)
24end 23end
25 24
26function m.tochars (str)
27 local cs = {}
28 for _, code in utf8.codes(str) do
29 table.insert(cs, code)
30 end
31 return cs
32end
33
34function m.constantly (x)
35 return function () return x end
36end
37
38-------- 25--------
39return m 26return m