From 9c5643d5f78e4228d47e293b421d7f388d47945f Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 19 Mar 2024 22:13:44 -0500 Subject: A new start! --- base.lua | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 base.lua (limited to 'base.lua') diff --git a/base.lua b/base.lua new file mode 100644 index 0000000..9c5b5b7 --- /dev/null +++ b/base.lua @@ -0,0 +1,37 @@ +--- lam.base --- base environment + +local base = {} +local type = require "type" +local isNull = type.isNull + +base.env = { + begin = + function (r) + local r = r + while not isNull(r.cdr) do + r = r.cdr + end + return r.car + end, + ["+"] = + function (r) + local r, a = r, 0 + while r.cdr do + r, a = r.cdr, a + r.car + end + return a + end, + ["-"] = + function (r) + if isNull(r) then return -1 end + if isNull(r.cdr) then return (- r.car) end + local r, a = r.cdr, r.car + while r.cdr do + r, a = r.cdr, a - r.car + end + return a + end, +} + +--- +return base -- cgit 1.4.1-21-gabe81