551 implementation of the inference kernel itself, which uses the very |
551 implementation of the inference kernel itself, which uses the very |
552 same data mechanisms for types, constants, axioms etc. |
552 same data mechanisms for types, constants, axioms etc. |
553 *} |
553 *} |
554 |
554 |
555 |
555 |
|
556 subsection {* Configuration options \label{sec:config-options} *} |
|
557 |
|
558 text {* A \emph{configuration option} is a named optional value of |
|
559 some basic type (Boolean, integer, string) that is stored in the |
|
560 context. It is a simple application of general context data |
|
561 (\secref{sec:context-data}) that is sufficiently common to justify |
|
562 customized setup, which includes some concrete declarations for |
|
563 end-users using existing notation for attributes (cf.\ |
|
564 \secref{sec:attributes}). |
|
565 |
|
566 For example, the predefined configuration option @{attribute |
|
567 show_types} controls output of explicit type constraints for |
|
568 variables in printed terms (cf.\ \secref{sec:parse-print}). Its |
|
569 value can be modified within Isar text like this: |
|
570 *} |
|
571 |
|
572 declare [[show_types = false]] |
|
573 -- {* declaration within (local) theory context *} |
|
574 |
|
575 example_proof |
|
576 note [[show_types = true]] |
|
577 -- {* declaration within proof (forward mode) *} |
|
578 term x |
|
579 |
|
580 have "x = x" |
|
581 using [[show_types = false]] |
|
582 -- {* declaration within proof (backward mode) *} |
|
583 .. |
|
584 qed |
|
585 |
|
586 text {* Configuration options that are not set explicitly hold a |
|
587 default value that can depend on the application context. This |
|
588 allows to retrieve the value from another slot within the context, |
|
589 or fall back on a global preference mechanism, for example. |
|
590 |
|
591 The operations to declare configuration options and get/map their |
|
592 values are modeled as direct replacements for historic global |
|
593 references, only that the context is made explicit. This allows |
|
594 easy configuration of tools, without relying on the execution order |
|
595 as required for old-style mutable references. *} |
|
596 |
|
597 text %mlref {* |
|
598 \begin{mldecls} |
|
599 @{index_ML Config.get: "Proof.context -> 'a Config.T -> 'a"} \\ |
|
600 @{index_ML Config.map: "'a Config.T -> ('a -> 'a) -> Proof.context -> Proof.context"} \\ |
|
601 @{index_ML Attrib.config_bool: "string -> (Context.generic -> bool) -> |
|
602 bool Config.T * (theory -> theory)"} \\ |
|
603 @{index_ML Attrib.config_int: "string -> (Context.generic -> int) -> |
|
604 int Config.T * (theory -> theory)"} \\ |
|
605 @{index_ML Attrib.config_string: "string -> (Context.generic -> string) -> |
|
606 string Config.T * (theory -> theory)"} \\ |
|
607 \end{mldecls} |
|
608 |
|
609 \begin{description} |
|
610 |
|
611 \item @{ML Config.get}~@{text "ctxt config"} gets the value of |
|
612 @{text "config"} in the given context. |
|
613 |
|
614 \item @{ML Config.map}~@{text "config f ctxt"} updates the context |
|
615 by updating the value of @{text "config"}. |
|
616 |
|
617 \item @{text "(config, setup) ="}~@{ML Attrib.config_bool}~@{text |
|
618 "name default"} creates a named configuration option of type |
|
619 @{ML_type bool}, with the given @{text "default"} depending on the |
|
620 application context. The resulting @{text "config"} can be used to |
|
621 get/map its value in a given context. The @{text "setup"} function |
|
622 needs to be applied to the theory initially, in order to make |
|
623 concrete declaration syntax available to the user. |
|
624 |
|
625 \item @{ML Attrib.config_int} and @{ML Attrib.config_string} work |
|
626 like @{ML Attrib.config_bool}, but for types @{ML_type int} and |
|
627 @{ML_type string}, respectively. |
|
628 |
|
629 \end{description} |
|
630 *} |
|
631 |
|
632 text %mlex {* The following example shows how to declare and use a |
|
633 Boolean configuration option called @{text "my_flag"} with constant |
|
634 default value @{ML false}. *} |
|
635 |
|
636 ML {* |
|
637 val (my_flag, my_flag_setup) = |
|
638 Attrib.config_bool "my_flag" (K false) |
|
639 *} |
|
640 setup my_flag_setup |
|
641 |
|
642 text {* Now the user can refer to @{attribute my_flag} in |
|
643 declarations, while we can retrieve the current value from the |
|
644 context via @{ML Config.get}. *} |
|
645 |
|
646 ML_val {* Config.get @{context} my_flag *} |
|
647 |
|
648 declare [[my_flag = true]] |
|
649 |
|
650 ML_val {* Config.get @{context} my_flag *} |
|
651 |
|
652 example_proof |
|
653 note [[my_flag = false]] |
|
654 ML_val {* Config.get @{context} my_flag *} |
|
655 qed |
|
656 |
|
657 ML_val {* Config.get @{context} my_flag *} |
|
658 |
|
659 |
556 section {* Names \label{sec:names} *} |
660 section {* Names \label{sec:names} *} |
557 |
661 |
558 text {* In principle, a name is just a string, but there are various |
662 text {* In principle, a name is just a string, but there are various |
559 conventions for representing additional structure. For example, |
663 conventions for representing additional structure. For example, |
560 ``@{text "Foo.bar.baz"}'' is considered as a long name consisting of |
664 ``@{text "Foo.bar.baz"}'' is considered as a long name consisting of |