about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2024-02-22 00:29:23 -0600
committerCase Duckworth2024-02-22 00:29:23 -0600
commit34d94104686fdb6e3bc2573315291770cab37cf3 (patch)
tree847181cf70c590ea1735586295583fa138102bc0
parentAdd global and types libraries (diff)
downloadlam-34d94104686fdb6e3bc2573315291770cab37cf3.tar.gz
lam-34d94104686fdb6e3bc2573315291770cab37cf3.zip
Change types to lowercase; add todos
-rw-r--r--eval.lua6
-rw-r--r--readme.txt17
-rw-r--r--types.lua13
3 files changed, 25 insertions, 11 deletions
diff --git a/eval.lua b/eval.lua index cdf4612..185268f 100644 --- a/eval.lua +++ b/eval.lua
@@ -10,7 +10,7 @@ local types = require("types")
10if not table.unpack then table.unpack = unpack end 10if not table.unpack then table.unpack = unpack end
11 11
12local function Env(inner, outer) 12local function Env(inner, outer)
13 return setmetatable(inner, { __type = "Environment", __index = outer, }) 13 return setmetatable(inner, { __type = "environment", __index = outer, })
14end 14end
15 15
16local function Proc(params, body, env) 16local function Proc(params, body, env)
@@ -20,7 +20,7 @@ local function Proc(params, body, env)
20 env = env, 20 env = env,
21 } 21 }
22 local mt = { 22 local mt = {
23 __type = "Procedure", 23 __type = "procedure",
24 __call = 24 __call =
25 function (self, ...) 25 function (self, ...)
26 local inner = {} 26 local inner = {}
@@ -37,7 +37,7 @@ end
37 37
38function eval.eval (x, e) 38function eval.eval (x, e)
39 e = e or global 39 e = e or global
40 if types.lamtype(x) == "Symbol" then 40 if types.lamtype(x) == "symbol" then
41 return e[x] 41 return e[x]
42 elseif types.luatype(x) ~= "table" then 42 elseif types.luatype(x) ~= "table" then
43 return x 43 return x
diff --git a/readme.txt b/readme.txt index 169c948..fd11f09 100644 --- a/readme.txt +++ b/readme.txt
@@ -20,8 +20,8 @@ you can set up a repl of lam to test it out:
20 20
21all of lua's math.* functions are available, as well as 21all of lua's math.* functions are available, as well as
22 22
23- + 23- +, *, /, -
24- * (more math functions to come!) 24- =, <, >, <=, >=
25- null? 25- null?
26- number? 26- number?
27- symbol? 27- symbol?
@@ -38,11 +38,24 @@ and special forms
38- define 38- define
39- lambda 39- lambda
40 40
41plus, some special lam functions:
42
43- luatype (the lua types of a value)
44- type (the lam type of the value)
45
41lam limitations 46lam limitations
42--------------- 47---------------
43 48
44- lam just has numbers and operations on them 49- lam just has numbers and operations on them
45- uh, and symbols. and lists. and lambdas and environments. 50- uh, and symbols. and lists. and lambdas and environments.
46 51
52todo
53----
54
55- move schemestr from repl into pp and expand (lua/lam pp, etc)
56- add more datatypes (strings, anyone?!)
57- numeric tower (oof) (at least exact/inexact numbers)
58- ....
59
47--------------------------- 60---------------------------
48contributions/help WELCOME! 61contributions/help WELCOME!
diff --git a/types.lua b/types.lua index dd105cf..d4c8d14 100644 --- a/types.lua +++ b/types.lua
@@ -6,21 +6,22 @@ types.luatype = type
6 6
7function types.lamtype (x) 7function types.lamtype (x)
8 if types.luatype(x) == "string" then 8 if types.luatype(x) == "string" then
9 return "Symbol" 9 return "symbol"
10 elseif types.luatype(x) == "number" then 10 elseif types.luatype(x) == "number" then
11 return "Number" 11 return "number"
12 elseif getmetatable(x) and getmetatable(x).__type then 12 elseif getmetatable(x) and getmetatable(x).__type then
13 return getmetatable(x).__type 13 return getmetatable(x).__type
14 elseif types.luatype(x) == "table" then 14 elseif types.luatype(x) == "table" then
15 return "List" 15 return "list"
16 else 16 else
17 return types.luatype(x) 17 return types.luatype(x)
18 end 18 end
19end 19end
20 20
21types["number?"] = function (x) return types.lamtype(x) == "Number" end 21types["number?"] = function (x) return types.lamtype(x) == "number" end
22types["symbol?"] = function (x) return types.lamtype(x) == "Symbol" end 22types["symbol?"] = function (x) return types.lamtype(x) == "symbol" end
23types["list?"] = function (x) return types.lamtype(x) == "List" end 23types["list?"] = function (x) return types.lamtype(x) == "list" end
24types["procedure?"] = function (x) return types.lamtype(x) == "procedure" end
24types["null?"] = function (x) return x == {} end 25types["null?"] = function (x) return x == {} end
25 26
26--- 27---