1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
% language=us
\usemodule[present-boring,abbreviations-logos]
\definehighlight[nb][style=bold,color=middlegray,define=no]
\setuptolerance[verytolerant,stretch]
\definecolor[maincolor][r=.3,b=.3]
\startdocument
[title={OVERLOAD PROTECTION},
banner={the downside of macros},
location={context\enspace {\bf 2021}\enspace meeting}]
% TEX MP
\starttitle[title=Primitives]
A \TEX\ engine comes with a whole set of primitive operations for:
\startitemize[packed]
\startitem
accessing internal variables
\stopitem
\startitem
defining macros
\stopitem
\startitem
controlling expansion
\stopitem
\startitem
constructing boxes
\stopitem
\startitem
finalizing pages
\stopitem
\startitem
defining characters (text and math)
\stopitem
\startitem
inserting kerns, glue and penalties
\stopitem
\startitem
defining fonts
\stopitem
\startitem
dealing with languages (hyphenation)
\stopitem
\startitem
testing properties
\stopitem
\startitem
manipulating tokens
\stopitem
\startitem
managing inserts
\stopitem
\startitem
handling marks
\stopitem
\startitem
grouping
\stopitem
\startitem
mathematics
\stopitem
\startitem
tracing
\stopitem
\stopitemize
\stoptitle
\starttitle[title=Macros]
\startitemize
\startitem
Macros are commands defined by the user and/or a macro package.
\stopitem
\startitem
They can overload a primitive which then can confuse the whole machinery.
\stopitem
\startitem
A macro package can alias primitives for instance \type {\relax} can be
replaced by \type {\foo_relax} after \typ {\let \foo_relax \relax}.
\stopitem
\startitem
That only when (at definition time) the \type {_} is a letter. By using such
a character some protection against overload is provided.
\stopitem
\startitem
In \CONTEXT\ we often use(d) aliases like \type {\normalrelax} but of course
these can also be overloaded.
\stopitem
\startitem
We only overload a very few primitives, for instance \type {\language}.
\stopitem
\startitem
Users who overload primitives are \quote {on their own} and \quote {without
support}.
\stopitem
\startitem
An easy way to protect yourself is using \type {\CamelCase} names.
\stopitem
\stopitemize
\stoptitle
\starttitle[title=Overload protection]
\startitemize
\startitem
The \LUAMETATEX\ engine has overload protection built in for the \TEX\ engine
as well as provides means to do that for \METAPOST.
\stopitem
\startitem
In \LMTX\ all commands have been tagged accordingly (which was quite some work).
\stopitem
\startitem
Processing \type {s-system-macros.mkxl} gives an overview.
\stopitem
\startitem
Overload protection is off by default but can be turned on:
\starttyping
\enabledirectives[overloadmode=warning]
\enabledirectives[overloadmode=error]
\stoptyping
\stopitem
\startitem
I myself always run with the error variant and make sure that the manuals obey
the rules.
\stopitem
\startitem
Modules and/or styles (and in a few cases the core code) can cheat and use:
\starttyping
\pushoverloadmode
........................
........................
\popoverloadmode
\stoptyping
\stopitem
\stopitemize
\stoptitle
\starttitle[title=Details]
\startitemize
\startitem
Traditional \TEX\ has a few so called prefixes: \type {\global}, \type {\outer},
\type {\long}, and type \type {\immediate}.
\stopitem
\startitem
The \ETEX\ engine adds \type {\protected} (because we already had that in
\CONTEXT\ we use what we (also already) had: \type {\unexpanded}).
\stopitem
\startitem
In \LUATEX\ we can force macros to be always long, something that we do
in \MKIV\ (as in \MKII).
\stopitem
\startitem
In \LUAMETATEX\ the \type {\outer} and \type {\long} prefixes have been
dropped (they are ignored).
\stopitem
\startitem
In \LUAMETATEX\ the \type {\protected} prefix acts like in other engines
but protection is implemented more naturally.
\stopitem
\startitem
In addition \LUAMETATEX\ has new prefixes: \type {\frozen}, \type
{\permanent}, \type {\immutable}, \type {\mutable}, \type {\noaligned},
\type {\instance}, \type {\untraced}, \type {\tolerant}, \type
{\overloaded}, \type {\aliased}, \type {\immediate} and an experimental
\type {\semiprotected},
\stopitem
\startitem
Some prefixes end up as properties of macros, some influence scanning (for instance
in alignments and when calling \LUA\ functions). There is no noticeable runtime
overhead.
\stopitem
\startitem
The \type {\meaningfull} primitive is like \type {\meaning} but also reports
properties set by prefixes; there is also \type {\meaningless}.
\stopitem
\stopitemize
\stoptitle
\starttitle[title=Prefixes]
Regular definitions:
\startitemize
\startitem
\type {\global}: defines a macro or sets a register value out of scope.
\stopitem
\startitem
\type {\outer}: is used to issue a warning when a macro defined as such was
used nested (just ignored in \LUAMETATEX).
\stopitem
\startitem
\type {\long}: triggers a warning when an argument of a macro contains a
\type {\par} equivalent (just ignored in \LUAMETATEX).
\stopitem
\startitem
\type {\protected}: makes a macro unexpandable (being itself) in an \type
{\edef} equivalent situation (where it can get out of hands).
\stopitem
\startitem
\type {\semiprotected}: is like \type {\protected} but the property is
ignored when \type {\semiexpanded} is applied.
\stopitem
\stopitemize
Special case:
\startitemize
\startitem
\type {\immediate}: tells a backend primitive to come into action
immediately instead of creating a delayed action (via a whatsit node). In
\LUAMETATEX\ we have no built|-|in backend so there is signals a \LUA\
interface function this property.
\stopitem
\stopitemize
\page
Scanning related:
\startitemize
\startitem
\type {\noaligned}: tags a macro as valid peek ahead macro when scanning
alignments; normally that only makes sense for \type {\protected} macros.
This permits cleaner macros in for instance table mechanisms (no
unexpected expansion side effects).
\stopitem
\startitem
\type {\untraced}: this flag makes a macro report itself as primitive in
traces which is sometimes nicer that presenting a user with some
confusing meaning.
\stopitem
\startitem
\type {\tolerant}: a prefix that makes the macro argument parser accept
all kind of new argument parsing options and continue when delimited
arguments fail. This makes macros with optional arguments produce less
noise when they are traced but more important, it makes for cleaner low
level interfaces.
\stopitem
\stopitemize
\page
Overload protection (primitives are protected against overloads by default):
\startitemize
\startitem
\type {\aliased}: create a reference (using \type {\let}) that also inherits the
properties.
\stopitem
\startitem
\type {\permanent}: sets a flag that makes a macro (or definition) immune for
redefinition.
\stopitem
\startitem
\type {\frozen}: prevents overloading but one can bypass that with some
more effort.
\stopitem
\startitem
\type {\immutable}: makes a (normally variable definition) fixed, for instance
constants.
\stopitem
\startitem
\type {\mutable}: a flag showing that this macro or definition can be used for
anything (so the macro package also has to assume that).
\stopitem
\startitem
\type {\instance}: just a flag that can be used to signal that a macro (or definition)
is an instance of a more general concept.
\stopitem
\startitem
\type {\overloaded}: bypass a frozen flag (property).
\stopitem
\stopitemize
\blank[2*big]
{\em Show some examples in the source code and editor.}
\stoptitle
\stopdocument
|