From 235026f7d5893be5c3e2307e6dc61424e1aa91d2 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 3 Apr 2024 22:45:59 -0500 Subject: Change pp -> dump Keep them 4 letter file name boiiii --- Makefile | 2 +- dump.lua | 36 ++++++++++++++++++++++++++++++++++++ pp.lua | 37 ------------------------------------- read.lua | 2 -- repl.lua | 2 +- 5 files changed, 38 insertions(+), 41 deletions(-) create mode 100644 dump.lua delete mode 100644 pp.lua diff --git a/Makefile b/Makefile index 51b3fc2..42349fb 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ LUA ?= rlwrap luajit \ - -e 'pp = require "pp"' \ + -e 'pp = require("dump").pp' \ -e 'eval = require "eval"' \ -e 'read = require "read"' \ -e 'type = require "type"' \ diff --git a/dump.lua b/dump.lua new file mode 100644 index 0000000..dc32096 --- /dev/null +++ b/dump.lua @@ -0,0 +1,36 @@ +--- lam.pp + +local m = {} +local type = require "type" + +function m.dump (x, lvl) + lvl = lvl or 0 + local space = string.rep(" ", lvl) + local output = "" + --[[if getmetatable(x) and getmetatable(x).__tostring then + output = output .. tostring(x) + else]]if type.luatype(x) == "table" then + local subo = "" + for k,v in pairs(x) do + if v == x then + v = "self" + else + v = m.dump(v, lvl+2) + end + subo = subo .. string.format("\n%s[%s] = %s,", + (space.." "), k, v) + end + output = output .. string.format("\n%s{%s\n%s}", + space, subo, space) + else + output = output .. tostring(x) + end + return output +end + +function m.pp (x) + print(m.dump(x)) +end + +--- +return m diff --git a/pp.lua b/pp.lua deleted file mode 100644 index 4d9d9af..0000000 --- a/pp.lua +++ /dev/null @@ -1,37 +0,0 @@ ---- lam.pp - -local pp = {} -local type = require "type" -local unpack = table.unpack or unpack - -function pp.dump (x, lvl) - lvl = lvl or 0 - local space = string.rep(" ", lvl) - local output = "" - --[[if getmetatable(x) and getmetatable(x).__tostring then - output = output .. tostring(x) - else]]if type.luatype(x) == "table" then - local subo = "" - for k,v in pairs(x) do - if v == x then - v = "self" - else - v = pp.dump(v, lvl+2) - end - subo = subo .. string.format("\n%s[%s] = %s,", - (space.." "), k, v) - end - output = output .. string.format("\n%s{%s\n%s}", - space, subo, space) - else - output = output .. tostring(x) - end - return output -end - -function pp.pp (x) - print(pp.dump(x)) -end - ---- -return pp diff --git a/read.lua b/read.lua index f8d6b09..8a154a1 100644 --- a/read.lua +++ b/read.lua @@ -5,8 +5,6 @@ local t = require "type" local utf8 = require "utf8" local pop = require("util").pop -local pp = require("pp").pp - -- TODO: -- - string reading -- - # syntax diff --git a/repl.lua b/repl.lua index 93e430c..a3fdf95 100644 --- a/repl.lua +++ b/repl.lua @@ -3,7 +3,7 @@ local m = {} local read = require("read") local eval = require("eval") -local pp = require("pp").pp +local pp = require("dump").pp local function schemeprint (x) -- if x == nil then return end -- cgit 1.4.1-21-gabe81