2 (* $Id$ *) |
2 (* $Id$ *) |
3 |
3 |
4 theory prelim imports base begin |
4 theory prelim imports base begin |
5 |
5 |
6 chapter {* Preliminaries *} |
6 chapter {* Preliminaries *} |
7 |
|
8 section {* Named entities *} |
|
9 |
|
10 text {* Named entities of different kinds (logical constant, type, |
|
11 type class, theorem, method etc.) live in separate name spaces. It is |
|
12 usually clear from the occurrence of a name which kind of entity it |
|
13 refers to. For example, proof method @{text "foo"} vs.\ theorem |
|
14 @{text "foo"} vs.\ logical constant @{text "foo"} are easily |
|
15 distinguished by means of the syntactic context. A notable exception |
|
16 are logical identifiers within a term (\secref{sec:terms}): constants, |
|
17 fixed variables, and bound variables all share the same identifier |
|
18 syntax, but are distinguished by their scope. |
|
19 |
|
20 Each name space is organized as a collection of \emph{qualified |
|
21 names}, which consist of a sequence of basic name components separated |
|
22 by dots: @{text "Bar.bar.foo"}, @{text "Bar.foo"}, and @{text "foo"} |
|
23 are examples for valid qualified names. Name components are |
|
24 subdivided into \emph{symbols}, which constitute the smallest textual |
|
25 unit in Isabelle --- raw characters are normally not encountered |
|
26 directly. *} |
|
27 |
|
28 |
|
29 subsection {* Strings of symbols *} |
|
30 |
|
31 text {* Isabelle strings consist of a sequence of |
|
32 symbols\glossary{Symbol}{The smalles unit of text in Isabelle, |
|
33 subsumes plain ASCII characters as well as an infinite collection of |
|
34 named symbols (for greek, math etc.).}, which are either packed as an |
|
35 actual @{text "string"}, or represented as a list. Each symbol is in |
|
36 itself a small string of the following form: |
|
37 |
|
38 \begin{enumerate} |
|
39 |
|
40 \item either a singleton ASCII character ``@{text "c"}'' (with |
|
41 character code 0--127), for example ``\verb,a,'', |
|
42 |
|
43 \item or a regular symbol ``\verb,\,\verb,<,@{text "ident"}\verb,>,'', |
|
44 for example ``\verb,\,\verb,<alpha>,'', |
|
45 |
|
46 \item or a control symbol ``\verb,\,\verb,<^,@{text |
|
47 "ident"}\verb,>,'', for example ``\verb,\,\verb,<^bold>,'', |
|
48 |
|
49 \item or a raw control symbol ``\verb,\,\verb,<^raw:,@{text |
|
50 "\<dots>"}\verb,>,'' where ``@{text "\<dots>"}'' refers to any |
|
51 printable ASCII character (excluding ``\verb,.,'' and ``\verb,>,'') or |
|
52 non-ASCII character, for example ``\verb,\,\verb,<^raw:$\sum_{i = 1}^n$>,'', |
|
53 |
|
54 \item or a numbered raw control symbol ``\verb,\,\verb,<^raw,@{text |
|
55 "nnn"}\verb,>, where @{text "nnn"} are digits, for example |
|
56 ``\verb,\,\verb,<^raw42>,''. |
|
57 |
|
58 \end{enumerate} |
|
59 |
|
60 The @{text "ident"} syntax for symbol names is @{text "letter (letter |
|
61 | digit)\<^sup>*"}, where @{text "letter = A..Za..Z"} and @{text |
|
62 "digit = 0..9"}. There are infinitely many regular symbols and |
|
63 control symbols available, but a certain collection of standard |
|
64 symbols is treated specifically. For example, |
|
65 ``\verb,\,\verb,<alpha>,'' is classified as a (non-ASCII) letter, |
|
66 which means it may occur within regular Isabelle identifier syntax. |
|
67 |
|
68 Output of symbols depends on the print mode (\secref{sec:print-mode}). |
|
69 For example, the standard {\LaTeX} setup of the Isabelle document |
|
70 preparation system would present ``\verb,\,\verb,<alpha>,'' as @{text |
|
71 "\<alpha>"}, and ``\verb,\,\verb,<^bold>,\verb,\,\verb,<alpha>,'' as @{text |
|
72 "\<^bold>\<alpha>"}. |
|
73 |
|
74 \medskip It is important to note that the character set underlying |
|
75 Isabelle symbols is plain 7-bit ASCII. Since 8-bit characters are |
|
76 passed through transparently, Isabelle may easily process actual |
|
77 Unicode/UCS data (using the well-known UTF-8 encoding, for example). |
|
78 Unicode provides its own collection of mathematical symbols, but there |
|
79 is presently no link to Isabelle's named ones; both kinds of symbols |
|
80 coexist independently. *} |
|
81 |
|
82 text %mlref {* |
|
83 \begin{mldecls} |
|
84 @{index_ML_type "Symbol.symbol"} \\ |
|
85 @{index_ML Symbol.explode: "string -> Symbol.symbol list"} \\ |
|
86 @{index_ML Symbol.is_letter: "Symbol.symbol -> bool"} \\ |
|
87 @{index_ML Symbol.is_digit: "Symbol.symbol -> bool"} \\ |
|
88 @{index_ML Symbol.is_quasi: "Symbol.symbol -> bool"} \\ |
|
89 @{index_ML Symbol.is_blank: "Symbol.symbol -> bool"} \\ |
|
90 @{index_ML_type "Symbol.sym"} \\ |
|
91 @{index_ML Symbol.decode: "Symbol.symbol -> Symbol.sym"} \\ |
|
92 \end{mldecls} |
|
93 |
|
94 \begin{description} |
|
95 |
|
96 \item @{ML_type "Symbol.symbol"} represents Isabelle symbols; this type |
|
97 is merely an alias for @{ML_type "string"}, but emphasizes the |
|
98 specific format encountered here. |
|
99 |
|
100 \item @{ML "Symbol.explode"}~@{text "s"} produces an actual symbol |
|
101 list from the packed form usually encountered as user input. This |
|
102 function replaces @{ML "String.explode"} for virtually all purposes |
|
103 of manipulating text in Isabelle! Plain @{text "implode"} may be |
|
104 used for the reverse operation. |
|
105 |
|
106 \item @{ML "Symbol.is_letter"}, @{ML "Symbol.is_digit"}, @{ML |
|
107 "Symbol.is_quasi"}, @{ML "Symbol.is_blank"} classify certain symbols |
|
108 (both ASCII and several named ones) according to fixed syntactic |
|
109 convections of Isabelle, e.g.\ see \cite{isabelle-isar-ref}. |
|
110 |
|
111 \item @{ML_type "Symbol.sym"} is a concrete datatype that represents |
|
112 the different kinds of symbols explicitly as @{ML "Symbol.Char"}, |
|
113 @{ML "Symbol.Sym"}, @{ML "Symbol.Ctrl"}, or @{ML "Symbol.Raw"}. |
|
114 |
|
115 \item @{ML "Symbol.decode"} converts the string representation of a |
|
116 symbol into the explicit datatype version. |
|
117 |
|
118 \end{description} |
|
119 *} |
|
120 |
|
121 |
|
122 subsection {* Simple names *} |
|
123 |
|
124 text FIXME |
|
125 |
|
126 |
|
127 subsection {* Qualified names and name spaces *} |
|
128 |
|
129 text %FIXME {* Qualified names are constructed according to implicit naming |
|
130 principles of the present context. |
|
131 |
|
132 |
|
133 The last component is called \emph{base name}; the remaining prefix of |
|
134 qualification may be empty. |
|
135 |
|
136 Some practical conventions help to organize named entities more |
|
137 systematically: |
|
138 |
|
139 \begin{itemize} |
|
140 |
|
141 \item Names are qualified first by the theory name, second by an |
|
142 optional ``structure''. For example, a constant @{text "c"} declared |
|
143 as part of a certain structure @{text "b"} (say a type definition) in |
|
144 theory @{text "A"} will be named @{text "A.b.c"} internally. |
|
145 |
|
146 \item |
|
147 |
|
148 \item |
|
149 |
|
150 \item |
|
151 |
|
152 \item |
|
153 |
|
154 \end{itemize} |
|
155 |
|
156 Names of different kinds of entities are basically independent, but |
|
157 some practical naming conventions relate them to each other. For |
|
158 example, a constant @{text "foo"} may be accompanied with theorems |
|
159 @{text "foo.intro"}, @{text "foo.elim"}, @{text "foo.simps"} etc. The |
|
160 same may happen for a type @{text "foo"}, which is then apt to cause |
|
161 clashes in the theorem name space! To avoid this, we occasionally |
|
162 follow an additional convention of suffixes that determine the |
|
163 original kind of entity that a name has been derived. For example, |
|
164 constant @{text "foo"} is associated with theorem @{text "foo.intro"}, |
|
165 type @{text "foo"} with theorem @{text "foo_type.intro"}, and type |
|
166 class @{text "foo"} with @{text "foo_class.intro"}. |
|
167 |
|
168 *} |
|
169 |
|
170 |
|
171 section {* Structured output *} |
|
172 |
|
173 subsection {* Pretty printing *} |
|
174 |
|
175 text FIXME |
|
176 |
|
177 subsection {* Output channels *} |
|
178 |
|
179 text FIXME |
|
180 |
|
181 subsection {* Print modes *} |
|
182 |
|
183 text FIXME |
|
184 |
|
185 |
7 |
186 section {* Contexts \label{sec:context} *} |
8 section {* Contexts \label{sec:context} *} |
187 |
9 |
188 text {* |
10 text {* |
189 A logical context represents the background that is taken for |
11 A logical context represents the background that is taken for |
360 |
182 |
361 text FIXME |
183 text FIXME |
362 |
184 |
363 text %mlref {* FIXME *} |
185 text %mlref {* FIXME *} |
364 |
186 |
|
187 |
|
188 section {* Named entities *} |
|
189 |
|
190 text {* Named entities of different kinds (logical constant, type, |
|
191 type class, theorem, method etc.) live in separate name spaces. It is |
|
192 usually clear from the occurrence of a name which kind of entity it |
|
193 refers to. For example, proof method @{text "foo"} vs.\ theorem |
|
194 @{text "foo"} vs.\ logical constant @{text "foo"} are easily |
|
195 distinguished by means of the syntactic context. A notable exception |
|
196 are logical identifiers within a term (\secref{sec:terms}): constants, |
|
197 fixed variables, and bound variables all share the same identifier |
|
198 syntax, but are distinguished by their scope. |
|
199 |
|
200 Each name space is organized as a collection of \emph{qualified |
|
201 names}, which consist of a sequence of basic name components separated |
|
202 by dots: @{text "Bar.bar.foo"}, @{text "Bar.foo"}, and @{text "foo"} |
|
203 are examples for valid qualified names. Name components are |
|
204 subdivided into \emph{symbols}, which constitute the smallest textual |
|
205 unit in Isabelle --- raw characters are normally not encountered |
|
206 directly. *} |
|
207 |
|
208 |
|
209 subsection {* Strings of symbols *} |
|
210 |
|
211 text {* Isabelle strings consist of a sequence of |
|
212 symbols\glossary{Symbol}{The smalles unit of text in Isabelle, |
|
213 subsumes plain ASCII characters as well as an infinite collection of |
|
214 named symbols (for greek, math etc.).}, which are either packed as an |
|
215 actual @{text "string"}, or represented as a list. Each symbol is in |
|
216 itself a small string of the following form: |
|
217 |
|
218 \begin{enumerate} |
|
219 |
|
220 \item either a singleton ASCII character ``@{text "c"}'' (with |
|
221 character code 0--127), for example ``\verb,a,'', |
|
222 |
|
223 \item or a regular symbol ``\verb,\,\verb,<,@{text "ident"}\verb,>,'', |
|
224 for example ``\verb,\,\verb,<alpha>,'', |
|
225 |
|
226 \item or a control symbol ``\verb,\,\verb,<^,@{text |
|
227 "ident"}\verb,>,'', for example ``\verb,\,\verb,<^bold>,'', |
|
228 |
|
229 \item or a raw control symbol ``\verb,\,\verb,<^raw:,@{text |
|
230 "\<dots>"}\verb,>,'' where ``@{text "\<dots>"}'' refers to any |
|
231 printable ASCII character (excluding ``\verb,.,'' and ``\verb,>,'') or |
|
232 non-ASCII character, for example ``\verb,\,\verb,<^raw:$\sum_{i = 1}^n$>,'', |
|
233 |
|
234 \item or a numbered raw control symbol ``\verb,\,\verb,<^raw,@{text |
|
235 "nnn"}\verb,>, where @{text "nnn"} are digits, for example |
|
236 ``\verb,\,\verb,<^raw42>,''. |
|
237 |
|
238 \end{enumerate} |
|
239 |
|
240 The @{text "ident"} syntax for symbol names is @{text "letter (letter |
|
241 | digit)\<^sup>*"}, where @{text "letter = A..Za..Z"} and @{text |
|
242 "digit = 0..9"}. There are infinitely many regular symbols and |
|
243 control symbols available, but a certain collection of standard |
|
244 symbols is treated specifically. For example, |
|
245 ``\verb,\,\verb,<alpha>,'' is classified as a (non-ASCII) letter, |
|
246 which means it may occur within regular Isabelle identifier syntax. |
|
247 |
|
248 Output of symbols depends on the print mode (\secref{sec:print-mode}). |
|
249 For example, the standard {\LaTeX} setup of the Isabelle document |
|
250 preparation system would present ``\verb,\,\verb,<alpha>,'' as @{text |
|
251 "\<alpha>"}, and ``\verb,\,\verb,<^bold>,\verb,\,\verb,<alpha>,'' as @{text |
|
252 "\<^bold>\<alpha>"}. |
|
253 |
|
254 \medskip It is important to note that the character set underlying |
|
255 Isabelle symbols is plain 7-bit ASCII. Since 8-bit characters are |
|
256 passed through transparently, Isabelle may easily process actual |
|
257 Unicode/UCS data (using the well-known UTF-8 encoding, for example). |
|
258 Unicode provides its own collection of mathematical symbols, but there |
|
259 is presently no link to Isabelle's named ones; both kinds of symbols |
|
260 coexist independently. *} |
|
261 |
|
262 text %mlref {* |
|
263 \begin{mldecls} |
|
264 @{index_ML_type "Symbol.symbol"} \\ |
|
265 @{index_ML Symbol.explode: "string -> Symbol.symbol list"} \\ |
|
266 @{index_ML Symbol.is_letter: "Symbol.symbol -> bool"} \\ |
|
267 @{index_ML Symbol.is_digit: "Symbol.symbol -> bool"} \\ |
|
268 @{index_ML Symbol.is_quasi: "Symbol.symbol -> bool"} \\ |
|
269 @{index_ML Symbol.is_blank: "Symbol.symbol -> bool"} \\ |
|
270 @{index_ML_type "Symbol.sym"} \\ |
|
271 @{index_ML Symbol.decode: "Symbol.symbol -> Symbol.sym"} \\ |
|
272 \end{mldecls} |
|
273 |
|
274 \begin{description} |
|
275 |
|
276 \item @{ML_type "Symbol.symbol"} represents Isabelle symbols; this type |
|
277 is merely an alias for @{ML_type "string"}, but emphasizes the |
|
278 specific format encountered here. |
|
279 |
|
280 \item @{ML "Symbol.explode"}~@{text "s"} produces an actual symbol |
|
281 list from the packed form usually encountered as user input. This |
|
282 function replaces @{ML "String.explode"} for virtually all purposes |
|
283 of manipulating text in Isabelle! Plain @{text "implode"} may be |
|
284 used for the reverse operation. |
|
285 |
|
286 \item @{ML "Symbol.is_letter"}, @{ML "Symbol.is_digit"}, @{ML |
|
287 "Symbol.is_quasi"}, @{ML "Symbol.is_blank"} classify certain symbols |
|
288 (both ASCII and several named ones) according to fixed syntactic |
|
289 convections of Isabelle, e.g.\ see \cite{isabelle-isar-ref}. |
|
290 |
|
291 \item @{ML_type "Symbol.sym"} is a concrete datatype that represents |
|
292 the different kinds of symbols explicitly as @{ML "Symbol.Char"}, |
|
293 @{ML "Symbol.Sym"}, @{ML "Symbol.Ctrl"}, or @{ML "Symbol.Raw"}. |
|
294 |
|
295 \item @{ML "Symbol.decode"} converts the string representation of a |
|
296 symbol into the explicit datatype version. |
|
297 |
|
298 \end{description} |
|
299 *} |
|
300 |
|
301 |
|
302 subsection {* Qualified names and name spaces *} |
|
303 |
|
304 text %FIXME {* Qualified names are constructed according to implicit naming |
|
305 principles of the present context. |
|
306 |
|
307 |
|
308 The last component is called \emph{base name}; the remaining prefix of |
|
309 qualification may be empty. |
|
310 |
|
311 Some practical conventions help to organize named entities more |
|
312 systematically: |
|
313 |
|
314 \begin{itemize} |
|
315 |
|
316 \item Names are qualified first by the theory name, second by an |
|
317 optional ``structure''. For example, a constant @{text "c"} declared |
|
318 as part of a certain structure @{text "b"} (say a type definition) in |
|
319 theory @{text "A"} will be named @{text "A.b.c"} internally. |
|
320 |
|
321 \item |
|
322 |
|
323 \item |
|
324 |
|
325 \item |
|
326 |
|
327 \item |
|
328 |
|
329 \end{itemize} |
|
330 |
|
331 Names of different kinds of entities are basically independent, but |
|
332 some practical naming conventions relate them to each other. For |
|
333 example, a constant @{text "foo"} may be accompanied with theorems |
|
334 @{text "foo.intro"}, @{text "foo.elim"}, @{text "foo.simps"} etc. The |
|
335 same may happen for a type @{text "foo"}, which is then apt to cause |
|
336 clashes in the theorem name space! To avoid this, we occasionally |
|
337 follow an additional convention of suffixes that determine the |
|
338 original kind of entity that a name has been derived. For example, |
|
339 constant @{text "foo"} is associated with theorem @{text "foo.intro"}, |
|
340 type @{text "foo"} with theorem @{text "foo_type.intro"}, and type |
|
341 class @{text "foo"} with @{text "foo_class.intro"}. |
|
342 |
|
343 *} |
|
344 |
|
345 |
|
346 section {* Structured output *} |
|
347 |
|
348 subsection {* Pretty printing *} |
|
349 |
|
350 text FIXME |
|
351 |
|
352 subsection {* Output channels *} |
|
353 |
|
354 text FIXME |
|
355 |
|
356 subsection {* Print modes *} |
|
357 |
|
358 text FIXME |
|
359 |
|
360 |
365 end |
361 end |