new_theory : string -> unit
Calling new_theory thy creates a new, and empty, theory segment having name thy. The theory segment which was current before the call becomes a parent of the new theory segment. The new theory therefore consists of the current theory extended with the new theory segment. The new theory segment replaces its parent as the current theory segment. The parent segment is exported to disk.
In the interests of interactive usability, the behaviour of new_theory has some special cases. First, if new_theory thy is called in a situation where the current theory segment is already called thy, then this is interpreted as the user wanting to restart the current segment. In that case, the current segment is wiped clean (types and constants declared in it are removed from the signature, and all definitions, theorems and axioms are deleted) but is otherwise unchanged (it keeps the same parents, for example).
Second, if the current theory segment is empty and named "scratch", then new_theory thy creates a new theory segment the parents of which are the parents of "scratch". (This situation is almost never visible to users.)
Failure also occurs if thy is the name of a currently loaded theory segment. In general, all theory names, whether loaded or not, should be distinct. Moreover, the names should be distinct even when case distinctions are ignored.
- current_theory(); > val it = "scratch" : string - parents "-"; > val it = ["list", "option"] : string list - new_theory "foo"; <<HOL message: Created theory "foo">> > val it = () : unit - parents "-"; > val it = ["list", "option"] : string list
- val def = new_definition("foo", Term `foo x = x + x`); > val def = |- !x. foo x = x + x : thm val thm = Q.store_thm("foo_thm", `foo x = 2 * x`, RW_TAC arith_ss [def]); > val thm = |- foo x = 2 * x : thm - new_theory "foo"; <<HOL message: Restarting theory "foo">> > val it = () : unit val def = new_definition("twice", Term `twice x = x + x`); > val def = |- !x. twice x = x + x : thm - curr_defs(); > val it = [("twice", |- !x. twice x = x + x)] : (string * thm) list