diff options
author | Case Duckworth | 2024-03-19 22:13:44 -0500 |
---|---|---|
committer | Case Duckworth | 2024-03-19 22:13:44 -0500 |
commit | 9c5643d5f78e4228d47e293b421d7f388d47945f (patch) | |
tree | 3925d137d7820622b38f183ad259475ff48b39e5 /base.lua | |
parent | Add QUOTE, QUASIQUOTE, UNQUOTE reading and generalize (diff) | |
download | lam-9c5643d5f78e4228d47e293b421d7f388d47945f.tar.gz lam-9c5643d5f78e4228d47e293b421d7f388d47945f.zip |
A new start!
Diffstat (limited to 'base.lua')
-rw-r--r-- | base.lua | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/base.lua b/base.lua new file mode 100644 index 0000000..9c5b5b7 --- /dev/null +++ b/base.lua | |||
@@ -0,0 +1,37 @@ | |||
1 | --- lam.base --- base environment | ||
2 | |||
3 | local base = {} | ||
4 | local type = require "type" | ||
5 | local isNull = type.isNull | ||
6 | |||
7 | base.env = { | ||
8 | begin = | ||
9 | function (r) | ||
10 | local r = r | ||
11 | while not isNull(r.cdr) do | ||
12 | r = r.cdr | ||
13 | end | ||
14 | return r.car | ||
15 | end, | ||
16 | ["+"] = | ||
17 | function (r) | ||
18 | local r, a = r, 0 | ||
19 | while r.cdr do | ||
20 | r, a = r.cdr, a + r.car | ||
21 | end | ||
22 | return a | ||
23 | end, | ||
24 | ["-"] = | ||
25 | function (r) | ||
26 | if isNull(r) then return -1 end | ||
27 | if isNull(r.cdr) then return (- r.car) end | ||
28 | local r, a = r.cdr, r.car | ||
29 | while r.cdr do | ||
30 | r, a = r.cdr, a - r.car | ||
31 | end | ||
32 | return a | ||
33 | end, | ||
34 | } | ||
35 | |||
36 | --- | ||
37 | return base | ||