author | wenzelm |
Mon, 11 Sep 2023 19:30:48 +0200 | |
changeset 78659 | b5f3d1051b13 |
parent 77777 | 13cee8c2ed8d |
child 80504 | 7ea69c26524b |
permissions | -rw-r--r-- |
28019 | 1 |
(* Title: Pure/General/properties.ML |
2 |
Author: Makarius |
|
3 |
||
4 |
Property lists. |
|
5 |
*) |
|
6 |
||
7 |
signature PROPERTIES = |
|
8 |
sig |
|
50842 | 9 |
type entry = string * string |
10 |
type T = entry list |
|
71465
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
wenzelm
parents:
51665
diff
changeset
|
11 |
val entry_ord: entry ord |
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
wenzelm
parents:
51665
diff
changeset
|
12 |
val ord: T ord |
28019 | 13 |
val defined: T -> string -> bool |
14 |
val get: T -> string -> string option |
|
50842 | 15 |
val put: entry -> T -> T |
28019 | 16 |
val remove: string -> T -> T |
77777 | 17 |
val make_string: string -> string -> T |
18 |
val make_int: string -> int -> T |
|
77772 | 19 |
val get_string: T -> string -> string |
20 |
val get_int: T -> string -> int |
|
21 |
val get_seconds: T -> string -> Time.time |
|
28019 | 22 |
end; |
23 |
||
24 |
structure Properties: PROPERTIES = |
|
25 |
struct |
|
26 |
||
50842 | 27 |
type entry = string * string; |
28 |
type T = entry list; |
|
28019 | 29 |
|
71465
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
wenzelm
parents:
51665
diff
changeset
|
30 |
val entry_ord = prod_ord string_ord string_ord; |
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
wenzelm
parents:
51665
diff
changeset
|
31 |
val ord = list_ord entry_ord; |
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
wenzelm
parents:
51665
diff
changeset
|
32 |
|
28019 | 33 |
fun defined (props: T) name = AList.defined (op =) props name; |
34 |
fun get (props: T) name = AList.lookup (op =) props name; |
|
43780 | 35 |
fun put entry (props: T) = AList.update (op =) entry props; |
28019 | 36 |
fun remove name (props: T) = AList.delete (op =) name props; |
37 |
||
77777 | 38 |
fun make_string k s = if s = "" then [] else [(k, s)]; |
39 |
fun make_int k i = if i = 0 then [] else [(k, Value.print_int i)]; |
|
40 |
||
77772 | 41 |
val get_string = the_default "" oo get; |
42 |
||
43 |
fun get_int props name = |
|
44 |
(case get props name of |
|
45 |
NONE => 0 |
|
46 |
| SOME s => Value.parse_int s); |
|
47 |
||
48 |
fun get_seconds props name = |
|
49 |
(case get props name of |
|
51665 | 50 |
NONE => Time.zeroTime |
51 |
| SOME s => Time.fromReal (the_default 0.0 (Real.fromString s))); |
|
52 |
||
28019 | 53 |
end; |