src/Pure/General/properties.ML
author wenzelm
Sat, 22 Feb 2014 20:52:43 +0100
changeset 55672 5e25cc741ab9
parent 51665 cba83c9f72b9
child 71465 910a081cca74
permissions -rw-r--r--
support for completion within the formal context; tuned signature;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28019
359764333bf4 Property lists.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/General/properties.ML
359764333bf4 Property lists.
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
359764333bf4 Property lists.
wenzelm
parents:
diff changeset
     3
359764333bf4 Property lists.
wenzelm
parents:
diff changeset
     4
Property lists.
359764333bf4 Property lists.
wenzelm
parents:
diff changeset
     5
*)
359764333bf4 Property lists.
wenzelm
parents:
diff changeset
     6
359764333bf4 Property lists.
wenzelm
parents:
diff changeset
     7
signature PROPERTIES =
359764333bf4 Property lists.
wenzelm
parents:
diff changeset
     8
sig
50842
777c6026ca93 tuned signature;
wenzelm
parents: 46830
diff changeset
     9
  type entry = string * string
777c6026ca93 tuned signature;
wenzelm
parents: 46830
diff changeset
    10
  type T = entry list
28019
359764333bf4 Property lists.
wenzelm
parents:
diff changeset
    11
  val defined: T -> string -> bool
359764333bf4 Property lists.
wenzelm
parents:
diff changeset
    12
  val get: T -> string -> string option
50842
777c6026ca93 tuned signature;
wenzelm
parents: 46830
diff changeset
    13
  val put: entry -> T -> T
28019
359764333bf4 Property lists.
wenzelm
parents:
diff changeset
    14
  val remove: string -> T -> T
51665
cba83c9f72b9 tuned signature;
wenzelm
parents: 50842
diff changeset
    15
  val seconds: T -> string -> Time.time
28019
359764333bf4 Property lists.
wenzelm
parents:
diff changeset
    16
end;
359764333bf4 Property lists.
wenzelm
parents:
diff changeset
    17
359764333bf4 Property lists.
wenzelm
parents:
diff changeset
    18
structure Properties: PROPERTIES =
359764333bf4 Property lists.
wenzelm
parents:
diff changeset
    19
struct
359764333bf4 Property lists.
wenzelm
parents:
diff changeset
    20
50842
777c6026ca93 tuned signature;
wenzelm
parents: 46830
diff changeset
    21
type entry = string * string;
777c6026ca93 tuned signature;
wenzelm
parents: 46830
diff changeset
    22
type T = entry list;
28019
359764333bf4 Property lists.
wenzelm
parents:
diff changeset
    23
359764333bf4 Property lists.
wenzelm
parents:
diff changeset
    24
fun defined (props: T) name = AList.defined (op =) props name;
359764333bf4 Property lists.
wenzelm
parents:
diff changeset
    25
fun get (props: T) name = AList.lookup (op =) props name;
43780
2cb2310d68b6 more uniform Properties in ML and Scala;
wenzelm
parents: 29606
diff changeset
    26
fun put entry (props: T) = AList.update (op =) entry props;
28019
359764333bf4 Property lists.
wenzelm
parents:
diff changeset
    27
fun remove name (props: T) = AList.delete (op =) name props;
359764333bf4 Property lists.
wenzelm
parents:
diff changeset
    28
51665
cba83c9f72b9 tuned signature;
wenzelm
parents: 50842
diff changeset
    29
fun seconds props name =
cba83c9f72b9 tuned signature;
wenzelm
parents: 50842
diff changeset
    30
  (case AList.lookup (op =) props name of
cba83c9f72b9 tuned signature;
wenzelm
parents: 50842
diff changeset
    31
    NONE => Time.zeroTime
cba83c9f72b9 tuned signature;
wenzelm
parents: 50842
diff changeset
    32
  | SOME s => Time.fromReal (the_default 0.0 (Real.fromString s)));
cba83c9f72b9 tuned signature;
wenzelm
parents: 50842
diff changeset
    33
28019
359764333bf4 Property lists.
wenzelm
parents:
diff changeset
    34
end;