src/HOL/ex/Multiquote.thy
author wenzelm
Thu Feb 01 20:44:19 2001 +0100 (2001-02-01)
changeset 11020 646c929b6293
parent 10838 9423817dee84
child 11586 d8a7f6318457
permissions -rw-r--r--
tuned
     1 (*  Title:      HOL/ex/Multiquote.thy
     2     ID:         $Id$
     3     Author:     Markus Wenzel, TU Muenchen
     4     License:    GPL (GNU GENERAL PUBLIC LICENSE)
     5 
     6 Multiple nested quotations and anti-quotations -- basically a
     7 generalized version of de-Bruijn representation.
     8 *)
     9 
    10 header {* Multiple nested quotations and anti-quotations *}
    11 
    12 theory Multiquote = Main:
    13 
    14 syntax
    15   "_quote" :: "'b => ('a => 'b)"	     (".'(_')." [0] 1000)
    16   "_antiquote" :: "('a => 'b) => 'b"         ("\<acute>_" [1000] 1000)
    17 
    18 parse_translation {*
    19   let
    20     fun antiquote_tr i (Const ("_antiquote", _) $ (t as Const ("_antiquote", _) $ _)) =
    21           skip_antiquote_tr i t
    22       | antiquote_tr i (Const ("_antiquote", _) $ t) =
    23           antiquote_tr i t $ Bound i
    24       | antiquote_tr i (t $ u) = antiquote_tr i t $ antiquote_tr i u
    25       | antiquote_tr i (Abs (x, T, t)) = Abs (x, T, antiquote_tr (i + 1) t)
    26       | antiquote_tr _ a = a
    27     and skip_antiquote_tr i ((c as Const ("_antiquote", _)) $ t) =
    28           c $ skip_antiquote_tr i t
    29       | skip_antiquote_tr i t = antiquote_tr i t;
    30 
    31     fun quote_tr [t] = Abs ("s", dummyT, antiquote_tr 0 (Term.incr_boundvars 1 t))
    32       | quote_tr ts = raise TERM ("quote_tr", ts);
    33   in [("_quote", quote_tr)] end
    34 *}
    35 
    36 text {* basic examples *}
    37 term ".(a + b + c)."
    38 term ".(a + b + c + \<acute>x + \<acute>y + 1)."
    39 term ".(\<acute>(f w) + \<acute>x)."
    40 term ".(f \<acute>x \<acute>y z)."
    41 
    42 text {* advanced examples *}
    43 term ".(.(\<acute>\<acute>x + \<acute>y).)."
    44 term ".(.(\<acute>\<acute>x + \<acute>y). \<circ> \<acute>f)."
    45 term ".(\<acute>(f \<circ> \<acute>g))."
    46 term ".(.( \<acute>\<acute>(f \<circ> \<acute>g) ).)."
    47 
    48 end