about summary refs log tree commit diff stats
path: root/types.lua
blob: d4c8d1453d3bc33c44675462524af669526e2481 (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
--- lam.types

local types = {}

types.luatype = type

function types.lamtype (x)
	if types.luatype(x) == "string" then
		return "symbol"
	elseif types.luatype(x) == "number" then
		return "number"
	elseif getmetatable(x) and getmetatable(x).__type then
		return getmetatable(x).__type
	elseif types.luatype(x) == "table" then
		return "list"
	else
		return types.luatype(x)
	end
end

types["number?"] = function (x) return types.lamtype(x) == "number" end
types["symbol?"] = function (x) return types.lamtype(x) == "symbol" end
types["list?"] = function (x) return types.lamtype(x) == "list" end
types["procedure?"] = function (x) return types.lamtype(x) == "procedure" end
types["null?"] = function (x) return x == {} end

---
return types