From fd3db5c3899daaaefba64479cdf73fcf9c8dbdf3 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 13 Apr 2024 18:02:05 -0500 Subject: Trim util --- core.lua | 8 +++----- read.lua | 7 ++++--- type.lua | 5 +++-- util.lua | 13 ------------- 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 @@ local dump = require("dump") local type = require("type") -local utf8 = require("utf8") -local null = type.null local assert_arity, assert_type = type.assert_arity, type.assert_type -local util = require("util") -local error = util.error +local null = type.null +local error = require("util").error local function fold (kons, knil, r) if r == null then @@ -111,7 +109,7 @@ end env["integer->char"] = function (r) assert_arity(r,1,1) assert_type(r[1], "number") -- todo: check integer - return type.character(utf8.char(r[1])) + return type.character(r[1]) end env["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 = {} local type = require("type") local eof, input_port = type.eof, type.input_port local util = require("util") -local constantly, error, pop = util.constantly, util.error, util.pop +local error, pop = util.error, util.pop +local utf8_char = require("utf8").char local token_separators = "[%s#()\"'`,@;]" @@ -127,7 +128,7 @@ local function consume_string_hexvalue (cs) table.insert(u8ch, c) until c == ";" table.remove(u8ch) -- discard ';' - return utf8.char(tonumber(table.concat(u8ch), 16)), cs + return utf8_char(tonumber(table.concat(u8ch), 16)), cs end local function consume_string (cs) @@ -258,7 +259,7 @@ m.readmacros = { table.insert(Q, m.read(port)) return type.list(Q) end, - comment = constantly(nil), -- throw comments away + comment = function (_,_,_) return nil end, } ---[[ READ ]]--- diff --git a/type.lua b/type.lua index 79f42a6..83b29f2 100644 --- a/type.lua +++ b/type.lua @@ -7,8 +7,9 @@ local m = {} local utf8 = require("utf8") -local util = require("util") -local tochars, error, constantly = util.tochars, util.error, util.constantly +local utf8_char, utf8_codepoint, utf8_codes = + utf8.char, utf8.codepoint, utf8.codes +local error = require("util").error ---[[ ATOMIC TYPES ]]--- diff --git a/util.lua b/util.lua index a13912c..7040e33 100644 --- a/util.lua +++ b/util.lua @@ -2,7 +2,6 @@ local m = {} local string = string -local utf8 = require("utf8") m.luaerror = error @@ -23,17 +22,5 @@ function m.pop (tbl) return table.remove(tbl, 1) end -function m.tochars (str) - local cs = {} - for _, code in utf8.codes(str) do - table.insert(cs, code) - end - return cs -end - -function m.constantly (x) - return function () return x end -end - -------- return m -- cgit 1.4.1-21-gabe81