2013-12-27 03:49:04 +00:00
|
|
|
import("util.lua")
|
2013-12-09 01:33:18 +00:00
|
|
|
local env = environment()
|
2014-01-01 21:52:25 +00:00
|
|
|
env:import("Int")
|
2013-12-09 01:33:18 +00:00
|
|
|
print(get_options())
|
|
|
|
parse_lean_cmds([[
|
2014-01-05 20:05:08 +00:00
|
|
|
variable f : Int -> Int -> Int
|
|
|
|
variable g : Bool -> Bool -> Bool
|
|
|
|
variables a b : Int
|
|
|
|
variables i j : Int
|
|
|
|
variables p q : Bool
|
|
|
|
notation 100 _ ++ _ : f
|
|
|
|
notation 100 _ ++ _ : g
|
|
|
|
setoption pp::colors true
|
|
|
|
setoption pp::width 300
|
2013-12-09 01:33:18 +00:00
|
|
|
]], env)
|
|
|
|
print(get_options())
|
|
|
|
assert(get_options():get{"pp", "colors"})
|
|
|
|
assert(get_options():get{"pp", "width"} == 300)
|
|
|
|
parse_lean_cmds([[
|
2014-01-05 19:03:35 +00:00
|
|
|
print i ++ j
|
|
|
|
print f i j
|
2013-12-09 01:33:18 +00:00
|
|
|
]], env)
|
|
|
|
|
|
|
|
local env2 = environment()
|
2014-01-01 21:52:25 +00:00
|
|
|
env2:import("Int")
|
2013-12-09 01:33:18 +00:00
|
|
|
parse_lean_cmds([[
|
2014-01-05 20:05:08 +00:00
|
|
|
variable f : Int -> Int -> Int
|
|
|
|
variables a b : Int
|
2014-01-05 19:03:35 +00:00
|
|
|
print f a b
|
2014-01-05 20:05:08 +00:00
|
|
|
notation 100 _ -+ _ : f
|
2013-12-09 01:33:18 +00:00
|
|
|
]], env2)
|
|
|
|
|
|
|
|
local f, a, b = Consts("f, a, b")
|
|
|
|
assert(tostring(f(a, b)) == "f a b")
|
|
|
|
set_formatter(lean_formatter(env))
|
|
|
|
assert(tostring(f(a, b)) == "a ++ b")
|
|
|
|
set_formatter(lean_formatter(env2))
|
2014-01-05 16:52:46 +00:00
|
|
|
assert(tostring(f(a, b)) == "a -+ b")
|
2013-12-09 01:33:18 +00:00
|
|
|
|
|
|
|
local fmt = lean_formatter(env)
|
|
|
|
-- We can parse commands with respect to environment env2,
|
|
|
|
-- but using a formatter based on env.
|
|
|
|
parse_lean_cmds([[
|
2014-01-05 19:03:35 +00:00
|
|
|
print f a b
|
2013-12-09 01:33:18 +00:00
|
|
|
]], env2, options(), fmt)
|
|
|
|
|
|
|
|
set_formatter(fmt)
|
|
|
|
env = nil
|
|
|
|
env2 = nil
|
|
|
|
fmt = nil
|
|
|
|
collectgarbage()
|
|
|
|
-- The references to env, env2 and fmt were removed, but The global
|
|
|
|
-- formatter (set with set_formatter) still has a reference to its
|
|
|
|
-- environment.
|
|
|
|
assert(tostring(f(a, b)) == "a ++ b")
|