about summary refs log tree commit diff stats
path: root/types.lua
diff options
context:
space:
mode:
authorCase Duckworth2024-02-22 00:23:32 -0600
committerCase Duckworth2024-02-22 00:23:32 -0600
commit5328b62221a3839dca117d71a4703f3ad719c9ce (patch)
tree7212235f569e765d3a4ebed0e8d21b64d905bf3a /types.lua
parentRemove spurious require (diff)
downloadlam-5328b62221a3839dca117d71a4703f3ad719c9ce.tar.gz
lam-5328b62221a3839dca117d71a4703f3ad719c9ce.zip
Add global and types libraries
Diffstat (limited to 'types.lua')
-rw-r--r--types.lua27
1 files changed, 27 insertions, 0 deletions
diff --git a/types.lua b/types.lua new file mode 100644 index 0000000..dd105cf --- /dev/null +++ b/types.lua
@@ -0,0 +1,27 @@
1--- lam.types
2
3local types = {}
4
5types.luatype = type
6
7function types.lamtype (x)
8 if types.luatype(x) == "string" then
9 return "Symbol"
10 elseif types.luatype(x) == "number" then
11 return "Number"
12 elseif getmetatable(x) and getmetatable(x).__type then
13 return getmetatable(x).__type
14 elseif types.luatype(x) == "table" then
15 return "List"
16 else
17 return types.luatype(x)
18 end
19end
20
21types["number?"] = function (x) return types.lamtype(x) == "Number" end
22types["symbol?"] = function (x) return types.lamtype(x) == "Symbol" end
23types["list?"] = function (x) return types.lamtype(x) == "List" end
24types["null?"] = function (x) return x == {} end
25
26---
27return types