about summary refs log tree commit diff stats
path: root/base.lua
blob: 9c5b5b7260c369254c64ad42d380f40a9cdff83b (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
30
31
32
33
34
35
36
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