heavlisp "improvements"

This commit is contained in:
2021-01-29 23:33:15 +00:00
parent 78d22d9f66
commit 5e67897a70
5 changed files with 63 additions and 5 deletions

View File

@@ -1426,7 +1426,8 @@ else
elseif textutils.unserialise(value) ~= nil then value = textutils.unserialise(value) end
potatOS.registry.set(key, value)
end
]]
]],
["/rom/heavlisp_lib/stdlib.hvl"] = fproxy "stdlib.hvl"
}
for _, file in pairs(fs.list "bin") do

52
src/stdlib.hvl Normal file
View File

@@ -0,0 +1,52 @@
(newvar '- [(+ arg1 (negate arg2))])
(newvar '-- [(- arg1 1)])
(newvar '++ [(+ arg1 1)])
(newvar '!! [
(if arg1 [false] [true])
])
(newvar 'ztb [
(if (== arg1 0) [false] [if (== arg1 false) [false] [true]])
])
(newvar 'ifz [
(if (ztb arg1) arg2 arg3)
])
(newvar 'inz [
(if (!! (ztb arg1)) arg2 arg3)
])
(newvar '! [
(inz arg1 [1] [(*
arg1
(! (-- arg1))
)])
])
(newvar 'for [
(if (arg2 arg1) [
(arg3 arg1)
(for (++ arg1) arg2 arg3)
][true])
])
(newvar 'inrng [
(for arg1 [(< arg1 (++ arg2))] arg3)
])
(newvar 'internal_in [
(newvar 'a arg1)
(newvar 'k (keys arg1) )
(inrng 1 (len arg1) [
(arg2 (at k arg1) (at a (at k arg1)))
])
])
(newvar 'in [
(internal_in arg1 arg2)
])
('exports
'- -
'-- --
'++ ++
'ifz ifz
'inz inz
'!! !!
'! !
'for for
'inrng inrng
'in in
)

View File

@@ -275,8 +275,12 @@ function interpret(ast,imports)
end
end
local function throwerror(reason)
print("line "..cline..": "..reason)
os.exit(1)
if os.exit then
print("line "..cline..": "..reason)
os.exit(1)
else
error("line "..cline..": "..reason)
end
end
local function get(k)
local t=top()