| author | blanchet | 
| Tue, 08 Apr 2014 18:06:21 +0200 | |
| changeset 56454 | e9e82384e5a1 | 
| parent 56158 | c2c6d560e7b2 | 
| child 57887 | 44354c99d754 | 
| permissions | -rw-r--r-- | 
| 
26281
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
1  | 
(* Title: Pure/facts.ML  | 
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
2  | 
Author: Makarius  | 
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
3  | 
|
| 26307 | 4  | 
Environment of named facts, optionally indexed by proposition.  | 
| 
26281
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
5  | 
*)  | 
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
6  | 
|
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
7  | 
signature FACTS =  | 
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
8  | 
sig  | 
| 55740 | 9  | 
val the_single: string * Position.T -> thm list -> thm  | 
| 
26336
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
10  | 
datatype interval = FromTo of int * int | From of int | Single of int  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
11  | 
datatype ref =  | 
| 26361 | 12  | 
Named of (string * Position.T) * interval list option |  | 
| 
26336
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
13  | 
Fact of string  | 
| 26361 | 14  | 
val named: string -> ref  | 
| 49887 | 15  | 
val string_of_selection: interval list option -> string  | 
| 
26336
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
16  | 
val string_of_ref: ref -> string  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
17  | 
val name_of_ref: ref -> string  | 
| 26366 | 18  | 
val pos_of_ref: ref -> Position.T  | 
| 
26336
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
19  | 
val map_name_of_ref: (string -> string) -> ref -> ref  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
20  | 
val select: ref -> thm list -> thm list  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
21  | 
val selections: string * thm list -> (ref * thm) list  | 
| 
26281
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
22  | 
type T  | 
| 26393 | 23  | 
val empty: T  | 
| 
33095
 
bbd52d2f8696
renamed NameSpace to Name_Space -- also to emphasize its subtle change in semantics;
 
wenzelm 
parents: 
33093 
diff
changeset
 | 
24  | 
val space_of: T -> Name_Space.T  | 
| 33163 | 25  | 
val is_concealed: T -> string -> bool  | 
| 56003 | 26  | 
val check: Context.generic -> T -> xstring * Position.T -> string  | 
| 
26664
 
167d879a89b0
renamed dest to dest_table, and extern to extern table;
 
wenzelm 
parents: 
26654 
diff
changeset
 | 
27  | 
val intern: T -> xstring -> string  | 
| 
42358
 
b47d41d9f4b5
Name_Space: proper configuration options long_names, short_names, unique_names instead of former unsynchronized references;
 
wenzelm 
parents: 
35408 
diff
changeset
 | 
28  | 
val extern: Proof.context -> T -> string -> xstring  | 
| 
56140
 
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
 
wenzelm 
parents: 
56137 
diff
changeset
 | 
29  | 
val markup_extern: Proof.context -> T -> string -> Markup.T * xstring  | 
| 27738 | 30  | 
val lookup: Context.generic -> T -> string -> (bool * thm list) option  | 
| 
56140
 
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
 
wenzelm 
parents: 
56137 
diff
changeset
 | 
31  | 
val retrieve: Context.generic -> T -> xstring * Position.T -> string * thm list  | 
| 26692 | 32  | 
val defined: T -> string -> bool  | 
33  | 
val fold_static: (string * thm list -> 'a -> 'a) -> T -> 'a -> 'a  | 
|
| 
56158
 
c2c6d560e7b2
more explicit treatment of verbose mode, which includes concealed entries;
 
wenzelm 
parents: 
56140 
diff
changeset
 | 
34  | 
val dest_static: bool -> T list -> T -> (string * thm list) list  | 
| 
26281
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
35  | 
val props: T -> thm list  | 
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
36  | 
val could_unify: T -> term -> thm list  | 
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
37  | 
val merge: T * T -> T  | 
| 49747 | 38  | 
  val add_static: Context.generic -> {strict: bool, index: bool} ->
 | 
39  | 
binding * thm list -> T -> string * T  | 
|
| 
47005
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
42375 
diff
changeset
 | 
40  | 
val add_dynamic: Context.generic -> binding * (Context.generic -> thm list) -> T -> string * T  | 
| 
26654
 
1f711934f221
disallow duplicate entries (weak version for merge);
 
wenzelm 
parents: 
26393 
diff
changeset
 | 
41  | 
val del: string -> T -> T  | 
| 
 
1f711934f221
disallow duplicate entries (weak version for merge);
 
wenzelm 
parents: 
26393 
diff
changeset
 | 
42  | 
val hide: bool -> string -> T -> T  | 
| 
26281
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
43  | 
end;  | 
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
44  | 
|
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
45  | 
structure Facts: FACTS =  | 
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
46  | 
struct  | 
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
47  | 
|
| 
26336
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
48  | 
(** fact references **)  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
49  | 
|
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
50  | 
fun the_single _ [th] : thm = th  | 
| 55740 | 51  | 
| the_single (name, pos) ths =  | 
52  | 
      error ("Expected singleton fact " ^ quote name ^
 | 
|
53  | 
" (length " ^ string_of_int (length ths) ^ ")" ^ Position.here pos);  | 
|
| 
26336
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
54  | 
|
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
55  | 
|
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
56  | 
(* datatype interval *)  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
57  | 
|
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
58  | 
datatype interval =  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
59  | 
FromTo of int * int |  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
60  | 
From of int |  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
61  | 
Single of int;  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
62  | 
|
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
63  | 
fun string_of_interval (FromTo (i, j)) = string_of_int i ^ "-" ^ string_of_int j  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
64  | 
| string_of_interval (From i) = string_of_int i ^ "-"  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
65  | 
| string_of_interval (Single i) = string_of_int i;  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
66  | 
|
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
67  | 
fun interval n iv =  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
68  | 
  let fun err () = raise Fail ("Bad interval specification " ^ string_of_interval iv) in
 | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
69  | 
(case iv of  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
70  | 
FromTo (i, j) => if i <= j then i upto j else err ()  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
71  | 
| From i => if i <= n then i upto n else err ()  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
72  | 
| Single i => [i])  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
73  | 
end;  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
74  | 
|
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
75  | 
|
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
76  | 
(* datatype ref *)  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
77  | 
|
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
78  | 
datatype ref =  | 
| 26361 | 79  | 
Named of (string * Position.T) * interval list option |  | 
| 
26336
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
80  | 
Fact of string;  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
81  | 
|
| 26361 | 82  | 
fun named name = Named ((name, Position.none), NONE);  | 
83  | 
||
| 55740 | 84  | 
fun name_of_ref (Named ((name, _), _)) = name  | 
85  | 
| name_of_ref (Fact _) = raise Fail "Illegal literal fact";  | 
|
86  | 
||
87  | 
fun pos_of_ref (Named ((_, pos), _)) = pos  | 
|
88  | 
| pos_of_ref (Fact _) = Position.none;  | 
|
89  | 
||
| 26361 | 90  | 
fun map_name_of_ref f (Named ((name, pos), is)) = Named ((f name, pos), is)  | 
| 
26336
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
91  | 
| map_name_of_ref _ r = r;  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
92  | 
|
| 49887 | 93  | 
fun string_of_selection NONE = ""  | 
94  | 
  | string_of_selection (SOME is) = enclose "(" ")" (commas (map string_of_interval is));
 | 
|
95  | 
||
96  | 
fun string_of_ref (Named ((name, _), sel)) = name ^ string_of_selection sel  | 
|
97  | 
| string_of_ref (Fact _) = raise Fail "Illegal literal fact";  | 
|
| 
26336
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
98  | 
|
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
99  | 
|
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
100  | 
(* select *)  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
101  | 
|
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
102  | 
fun select (Fact _) ths = ths  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
103  | 
| select (Named (_, NONE)) ths = ths  | 
| 26361 | 104  | 
| select (Named ((name, pos), SOME ivs)) ths =  | 
| 
26336
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
105  | 
let  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
106  | 
val n = length ths;  | 
| 26361 | 107  | 
fun err msg =  | 
| 55740 | 108  | 
error (msg ^ " for fact " ^ quote name ^ " (length " ^ string_of_int n ^ ")" ^  | 
| 48992 | 109  | 
Position.here pos);  | 
| 
26336
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
110  | 
fun sel i =  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
111  | 
          if i < 1 orelse i > n then err ("Bad subscript " ^ string_of_int i)
 | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
112  | 
else nth ths (i - 1);  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
113  | 
val is = maps (interval n) ivs handle Fail msg => err msg;  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
114  | 
in map sel is end;  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
115  | 
|
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
116  | 
|
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
117  | 
(* selections *)  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
118  | 
|
| 26361 | 119  | 
fun selections (name, [th]) = [(Named ((name, Position.none), NONE), th)]  | 
120  | 
| selections (name, ths) = map2 (fn i => fn th =>  | 
|
121  | 
(Named ((name, Position.none), SOME [Single i]), th)) (1 upto length ths) ths;  | 
|
| 
26336
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
122  | 
|
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
123  | 
|
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
124  | 
|
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
125  | 
(** fact environment **)  | 
| 
 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 
wenzelm 
parents: 
26307 
diff
changeset
 | 
126  | 
|
| 26393 | 127  | 
(* datatypes *)  | 
128  | 
||
129  | 
datatype fact = Static of thm list | Dynamic of Context.generic -> thm list;  | 
|
| 
26281
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
130  | 
|
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
131  | 
datatype T = Facts of  | 
| 
33095
 
bbd52d2f8696
renamed NameSpace to Name_Space -- also to emphasize its subtle change in semantics;
 
wenzelm 
parents: 
33093 
diff
changeset
 | 
132  | 
 {facts: fact Name_Space.table,
 | 
| 
26281
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
133  | 
props: thm Net.net};  | 
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
134  | 
|
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
135  | 
fun make_facts facts props = Facts {facts = facts, props = props};
 | 
| 33163 | 136  | 
|
| 33096 | 137  | 
val empty = make_facts (Name_Space.empty_table "fact") Net.empty;  | 
| 
26281
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
138  | 
|
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
139  | 
|
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
140  | 
(* named facts *)  | 
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
141  | 
|
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
142  | 
fun facts_of (Facts {facts, ...}) = facts;
 | 
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
143  | 
|
| 56025 | 144  | 
val space_of = Name_Space.space_of_table o facts_of;  | 
| 26393 | 145  | 
|
| 33163 | 146  | 
val is_concealed = Name_Space.is_concealed o space_of;  | 
147  | 
||
| 56003 | 148  | 
fun check context facts (xname, pos) =  | 
149  | 
let  | 
|
150  | 
val (name, fact) = Name_Space.check context (facts_of facts) (xname, pos);  | 
|
151  | 
val _ =  | 
|
152  | 
(case fact of  | 
|
153  | 
Static _ => ()  | 
|
154  | 
| Dynamic _ => Context_Position.report_generic context pos (Markup.dynamic_fact name));  | 
|
155  | 
in name end;  | 
|
156  | 
||
| 
33095
 
bbd52d2f8696
renamed NameSpace to Name_Space -- also to emphasize its subtle change in semantics;
 
wenzelm 
parents: 
33093 
diff
changeset
 | 
157  | 
val intern = Name_Space.intern o space_of;  | 
| 
42358
 
b47d41d9f4b5
Name_Space: proper configuration options long_names, short_names, unique_names instead of former unsynchronized references;
 
wenzelm 
parents: 
35408 
diff
changeset
 | 
158  | 
fun extern ctxt = Name_Space.extern ctxt o space_of;  | 
| 
56140
 
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
 
wenzelm 
parents: 
56137 
diff
changeset
 | 
159  | 
fun markup_extern ctxt = Name_Space.markup_extern ctxt o space_of  | 
| 
26664
 
167d879a89b0
renamed dest to dest_table, and extern to extern table;
 
wenzelm 
parents: 
26654 
diff
changeset
 | 
160  | 
|
| 
56158
 
c2c6d560e7b2
more explicit treatment of verbose mode, which includes concealed entries;
 
wenzelm 
parents: 
56140 
diff
changeset
 | 
161  | 
|
| 
 
c2c6d560e7b2
more explicit treatment of verbose mode, which includes concealed entries;
 
wenzelm 
parents: 
56140 
diff
changeset
 | 
162  | 
(* retrieve *)  | 
| 
 
c2c6d560e7b2
more explicit treatment of verbose mode, which includes concealed entries;
 
wenzelm 
parents: 
56140 
diff
changeset
 | 
163  | 
|
| 56025 | 164  | 
val defined = is_some oo (Name_Space.lookup_key o facts_of);  | 
| 26692 | 165  | 
|
| 26393 | 166  | 
fun lookup context facts name =  | 
| 56025 | 167  | 
(case Name_Space.lookup_key (facts_of facts) name of  | 
| 26393 | 168  | 
NONE => NONE  | 
| 56025 | 169  | 
| SOME (_, Static ths) => SOME (true, ths)  | 
170  | 
| SOME (_, Dynamic f) => SOME (false, f context));  | 
|
| 26393 | 171  | 
|
| 
56140
 
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
 
wenzelm 
parents: 
56137 
diff
changeset
 | 
172  | 
fun retrieve context facts (xname, pos) =  | 
| 
 
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
 
wenzelm 
parents: 
56137 
diff
changeset
 | 
173  | 
let  | 
| 
 
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
 
wenzelm 
parents: 
56137 
diff
changeset
 | 
174  | 
val name = check context facts (xname, pos);  | 
| 
 
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
 
wenzelm 
parents: 
56137 
diff
changeset
 | 
175  | 
val thms =  | 
| 
 
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
 
wenzelm 
parents: 
56137 
diff
changeset
 | 
176  | 
(case lookup context facts name of  | 
| 
 
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
 
wenzelm 
parents: 
56137 
diff
changeset
 | 
177  | 
SOME (static, thms) =>  | 
| 
 
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
 
wenzelm 
parents: 
56137 
diff
changeset
 | 
178  | 
(if static then ()  | 
| 
 
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
 
wenzelm 
parents: 
56137 
diff
changeset
 | 
179  | 
else Context_Position.report_generic context pos (Markup.dynamic_fact name);  | 
| 
 
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
 
wenzelm 
parents: 
56137 
diff
changeset
 | 
180  | 
thms)  | 
| 
 
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
 
wenzelm 
parents: 
56137 
diff
changeset
 | 
181  | 
      | NONE => error ("Unknown fact " ^ quote name ^ Position.here pos));
 | 
| 
 
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
 
wenzelm 
parents: 
56137 
diff
changeset
 | 
182  | 
in (name, map (Thm.transfer (Context.theory_of context)) thms) end;  | 
| 
 
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
 
wenzelm 
parents: 
56137 
diff
changeset
 | 
183  | 
|
| 
56158
 
c2c6d560e7b2
more explicit treatment of verbose mode, which includes concealed entries;
 
wenzelm 
parents: 
56140 
diff
changeset
 | 
184  | 
|
| 
 
c2c6d560e7b2
more explicit treatment of verbose mode, which includes concealed entries;
 
wenzelm 
parents: 
56140 
diff
changeset
 | 
185  | 
(* static content *)  | 
| 
 
c2c6d560e7b2
more explicit treatment of verbose mode, which includes concealed entries;
 
wenzelm 
parents: 
56140 
diff
changeset
 | 
186  | 
|
| 
33093
 
d010f61d3702
eliminated separate stamp -- NameSpace.define/merge etc. ensure uniqueness already;
 
wenzelm 
parents: 
29848 
diff
changeset
 | 
187  | 
fun fold_static f =  | 
| 56025 | 188  | 
Name_Space.fold_table (fn (name, Static ths) => f (name, ths) | _ => I) o facts_of;  | 
| 26393 | 189  | 
|
| 
56158
 
c2c6d560e7b2
more explicit treatment of verbose mode, which includes concealed entries;
 
wenzelm 
parents: 
56140 
diff
changeset
 | 
190  | 
fun dest_static verbose prev_facts facts =  | 
| 27175 | 191  | 
fold_static (fn (name, ths) =>  | 
| 
56158
 
c2c6d560e7b2
more explicit treatment of verbose mode, which includes concealed entries;
 
wenzelm 
parents: 
56140 
diff
changeset
 | 
192  | 
if exists (fn prev => defined prev name) prev_facts orelse  | 
| 
 
c2c6d560e7b2
more explicit treatment of verbose mode, which includes concealed entries;
 
wenzelm 
parents: 
56140 
diff
changeset
 | 
193  | 
not verbose andalso is_concealed facts name then I  | 
| 
 
c2c6d560e7b2
more explicit treatment of verbose mode, which includes concealed entries;
 
wenzelm 
parents: 
56140 
diff
changeset
 | 
194  | 
else cons (name, ths)) facts []  | 
| 
 
c2c6d560e7b2
more explicit treatment of verbose mode, which includes concealed entries;
 
wenzelm 
parents: 
56140 
diff
changeset
 | 
195  | 
|> sort_wrt #1;  | 
| 
26281
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
196  | 
|
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
197  | 
|
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
198  | 
(* indexed props *)  | 
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
199  | 
|
| 35408 | 200  | 
val prop_ord = Term_Ord.term_ord o pairself Thm.full_prop_of;  | 
| 
26281
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
201  | 
|
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
202  | 
fun props (Facts {props, ...}) = sort_distinct prop_ord (Net.content props);
 | 
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
203  | 
fun could_unify (Facts {props, ...}) = Net.unify_term props;
 | 
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
204  | 
|
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
205  | 
|
| 26393 | 206  | 
(* merge facts *)  | 
| 
26281
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
207  | 
|
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
208  | 
fun merge (Facts {facts = facts1, props = props1}, Facts {facts = facts2, props = props2}) =
 | 
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
209  | 
let  | 
| 
33095
 
bbd52d2f8696
renamed NameSpace to Name_Space -- also to emphasize its subtle change in semantics;
 
wenzelm 
parents: 
33093 
diff
changeset
 | 
210  | 
val facts' = Name_Space.merge_tables (facts1, facts2);  | 
| 
56137
 
af71fb1cb31f
minor tuning -- NB: props are usually empty for global facts;
 
wenzelm 
parents: 
56025 
diff
changeset
 | 
211  | 
val props' =  | 
| 
 
af71fb1cb31f
minor tuning -- NB: props are usually empty for global facts;
 
wenzelm 
parents: 
56025 
diff
changeset
 | 
212  | 
if Net.is_empty props2 then props1  | 
| 
 
af71fb1cb31f
minor tuning -- NB: props are usually empty for global facts;
 
wenzelm 
parents: 
56025 
diff
changeset
 | 
213  | 
else if Net.is_empty props1 then props2  | 
| 
 
af71fb1cb31f
minor tuning -- NB: props are usually empty for global facts;
 
wenzelm 
parents: 
56025 
diff
changeset
 | 
214  | 
else Net.merge (is_equal o prop_ord) (props1, props2); (*beware of non-canonical merge*)  | 
| 
26281
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
215  | 
in make_facts facts' props' end;  | 
| 
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
216  | 
|
| 26393 | 217  | 
|
| 
26654
 
1f711934f221
disallow duplicate entries (weak version for merge);
 
wenzelm 
parents: 
26393 
diff
changeset
 | 
218  | 
(* add static entries *)  | 
| 26393 | 219  | 
|
| 49747 | 220  | 
fun add_static context {strict, index} (b, ths) (Facts {facts, props}) =
 | 
| 
26281
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
221  | 
let  | 
| 
33093
 
d010f61d3702
eliminated separate stamp -- NameSpace.define/merge etc. ensure uniqueness already;
 
wenzelm 
parents: 
29848 
diff
changeset
 | 
222  | 
val (name, facts') =  | 
| 
 
d010f61d3702
eliminated separate stamp -- NameSpace.define/merge etc. ensure uniqueness already;
 
wenzelm 
parents: 
29848 
diff
changeset
 | 
223  | 
      if Binding.is_empty b then ("", facts)
 | 
| 
47005
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
42375 
diff
changeset
 | 
224  | 
else Name_Space.define context strict (b, Static ths) facts;  | 
| 49747 | 225  | 
val props' = props  | 
226  | 
|> index ? fold (fn th => Net.insert_term (K false) (Thm.full_prop_of th, th)) ths;  | 
|
| 28864 | 227  | 
in (name, make_facts facts' props') end;  | 
| 
26281
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
228  | 
|
| 26393 | 229  | 
|
| 
26654
 
1f711934f221
disallow duplicate entries (weak version for merge);
 
wenzelm 
parents: 
26393 
diff
changeset
 | 
230  | 
(* add dynamic entries *)  | 
| 26393 | 231  | 
|
| 
47005
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
42375 
diff
changeset
 | 
232  | 
fun add_dynamic context (b, f) (Facts {facts, props}) =
 | 
| 
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
42375 
diff
changeset
 | 
233  | 
let val (name, facts') = Name_Space.define context true (b, Dynamic f) facts;  | 
| 
33093
 
d010f61d3702
eliminated separate stamp -- NameSpace.define/merge etc. ensure uniqueness already;
 
wenzelm 
parents: 
29848 
diff
changeset
 | 
234  | 
in (name, make_facts facts' props) end;  | 
| 
26281
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
235  | 
|
| 
26654
 
1f711934f221
disallow duplicate entries (weak version for merge);
 
wenzelm 
parents: 
26393 
diff
changeset
 | 
236  | 
|
| 
 
1f711934f221
disallow duplicate entries (weak version for merge);
 
wenzelm 
parents: 
26393 
diff
changeset
 | 
237  | 
(* remove entries *)  | 
| 
 
1f711934f221
disallow duplicate entries (weak version for merge);
 
wenzelm 
parents: 
26393 
diff
changeset
 | 
238  | 
|
| 56025 | 239  | 
fun del name (Facts {facts, props}) =
 | 
240  | 
make_facts (Name_Space.del_table name facts) props;  | 
|
| 
26654
 
1f711934f221
disallow duplicate entries (weak version for merge);
 
wenzelm 
parents: 
26393 
diff
changeset
 | 
241  | 
|
| 56025 | 242  | 
fun hide fully name (Facts {facts, props}) =
 | 
243  | 
make_facts (Name_Space.hide_table fully name facts) props;  | 
|
| 
26654
 
1f711934f221
disallow duplicate entries (weak version for merge);
 
wenzelm 
parents: 
26393 
diff
changeset
 | 
244  | 
|
| 
26281
 
328fd1c551ef
Environment of named facts (admits overriding).  Optional indexing by proposition.
 
wenzelm 
parents:  
diff
changeset
 | 
245  | 
end;  |