CookBook/Recipes/Config.thy
author boehmes
Wed, 07 Jan 2009 16:29:49 +0100
changeset 61 64c9540f2f84
child 63 83cea5dc6bac
permissions -rw-r--r--
Added four recipes.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
61
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
     1
theory Config
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
     2
imports Base
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
     3
begin
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
     4
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
     5
section {* Configuration Options *} 
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
     6
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
     7
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
     8
text {*
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
     9
  {\bf Problem:} 
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    10
  You would like to enhance your tool with options which can be changed later on
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    11
  by the user.\smallskip
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    12
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    13
  {\bf Solution:} This can be achieved using configuration values.\smallskip
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    14
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    15
  *}
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    16
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    17
ML {*
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    18
val (bvalue, setup_bvalue) = Attrib.config_bool "bvalue" false
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    19
val (ivalue, setup_ivalue) = Attrib.config_int "ivalue" 0
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    20
val (svalue, setup_svalue) = Attrib.config_string "svalue" "some string"
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    21
*}
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    22
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    23
setup "setup_bvalue o setup_ivalue o setup_svalue"
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    24
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    25
declare [[bvalue = true, ivalue = 3]]
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    26
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    27
text {*
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    28
  Note that this works without introducing a new command to modify the 
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    29
  configuration options. *}
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    30
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    31
ML {*
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    32
Config.get @{context} bvalue
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    33
*}
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    34
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    35
ML {*
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    36
Config.get_thy @{theory} ivalue
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    37
*}
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    38
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    39
setup {* Config.put_thy svalue "foo" *}
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    40
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    41
ML {* 
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    42
Config.get @{context} svalue
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    43
*}
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    44
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    45
ML {*
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    46
let val ctxt = Config.map ivalue (fn i => i + 1) @{context}
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    47
in Config.get ctxt ivalue end
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    48
*}
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    49
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    50
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    51
text {*
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    52
  Code: Pure/Isar/attrib.ML, Pure/config.ML
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    53
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    54
  Note: Avoid to use references for this purpose!
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    55
  *}
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    56
64c9540f2f84 Added four recipes.
boehmes
parents:
diff changeset
    57
end