diff options
-rw-r--r-- | eval.lua | 6 | ||||
-rw-r--r-- | readme.txt | 17 | ||||
-rw-r--r-- | types.lua | 13 |
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") | |||
10 | if not table.unpack then table.unpack = unpack end | 10 | if not table.unpack then table.unpack = unpack end |
11 | 11 | ||
12 | local function Env(inner, outer) | 12 | local function Env(inner, outer) |
13 | return setmetatable(inner, { __type = "Environment", __index = outer, }) | 13 | return setmetatable(inner, { __type = "environment", __index = outer, }) |
14 | end | 14 | end |
15 | 15 | ||
16 | local function Proc(params, body, env) | 16 | local 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 | ||
38 | function eval.eval (x, e) | 38 | function 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 | ||
21 | all of lua's math.* functions are available, as well as | 21 | all 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 | ||
41 | plus, some special lam functions: | ||
42 | |||
43 | - luatype (the lua types of a value) | ||
44 | - type (the lam type of the value) | ||
45 | |||
41 | lam limitations | 46 | lam 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 | ||
52 | todo | ||
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 | --------------------------- |
48 | contributions/help WELCOME! | 61 | contributions/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 | ||
7 | function types.lamtype (x) | 7 | function 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 |
19 | end | 19 | end |
20 | 20 | ||
21 | types["number?"] = function (x) return types.lamtype(x) == "Number" end | 21 | types["number?"] = function (x) return types.lamtype(x) == "number" end |
22 | types["symbol?"] = function (x) return types.lamtype(x) == "Symbol" end | 22 | types["symbol?"] = function (x) return types.lamtype(x) == "symbol" end |
23 | types["list?"] = function (x) return types.lamtype(x) == "List" end | 23 | types["list?"] = function (x) return types.lamtype(x) == "list" end |
24 | types["procedure?"] = function (x) return types.lamtype(x) == "procedure" end | ||
24 | types["null?"] = function (x) return x == {} end | 25 | types["null?"] = function (x) return x == {} end |
25 | 26 | ||
26 | --- | 27 | --- |