2013-11-14 00:07:15 +00:00
|
|
|
Variable x : Bool
|
|
|
|
|
|
|
|
(**
|
|
|
|
local env = get_environment()
|
|
|
|
local Int = Const("Int")
|
2013-11-14 23:17:00 +00:00
|
|
|
local plus = Const{"Int", "add"}
|
2013-11-14 00:07:15 +00:00
|
|
|
local x1, x2 = Consts("x1, x2")
|
2013-12-22 19:51:38 +00:00
|
|
|
print(env:type_check(Int))
|
|
|
|
print(env:type_check(plus))
|
2013-11-14 00:07:15 +00:00
|
|
|
env:add_var("x1", Int)
|
|
|
|
env:add_var("x2", Int)
|
|
|
|
print(plus(x1, x2))
|
2013-12-22 19:51:38 +00:00
|
|
|
print(env:type_check(plus(x1)))
|
2013-11-14 00:07:15 +00:00
|
|
|
|
|
|
|
function sum(...)
|
|
|
|
local args = {...}
|
|
|
|
if #args == 0 then
|
|
|
|
error("sum must have at least one argument")
|
|
|
|
else
|
|
|
|
local r = args[1]
|
|
|
|
for i = 2, #args do
|
|
|
|
r = plus(r, args[i])
|
|
|
|
end
|
|
|
|
return r
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local s = sum(x1, x1, x1, x2, x2)
|
|
|
|
print(s)
|
2013-12-22 19:51:38 +00:00
|
|
|
print(env:type_check(s))
|
2013-11-14 00:07:15 +00:00
|
|
|
env:add_definition("sum1", s)
|
|
|
|
**)
|
|
|
|
|
|
|
|
Show Environment 1
|
|
|
|
Eval sum1
|
|
|
|
Variable y : Bool
|