about summary refs log tree commit diff stats
path: root/base.lua
blob: 6dc71e4e413175d799e77368db36398833aa2bf6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
--- lam.base --- base environment

local base = {}
local type = require "type"
local isNull = type.isNull

base.env = {
	["+"] =
		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