aboutsummaryrefslogtreecommitdiffstats
path: root/doc/expert/pre_cont
blob: 90bf9e75da5ac25653597642f55c67923860e319 (plain) (blame)
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
@Section
   @Title { "@SetContext" and "@GetContext" }
   @Tag { cont }
@Begin
@PP
As earlier sections showed, the style information contains many
attributes:  the current font, break style, colour and texture,
and so on.  It is also possible
@FootNote { From Version 3.34 of Basser Lout. }
to add arbitrary additional information to the style, using the
@@SetContext symbol, and retrieve it using @@GetContext.  For example,
@ID @OneRow @Code @Verbatim {
{dirn @Yield up} @SetContext {
The current direction is {@GetContext dirn}.
}
}
produces
@ID @OneRow {
{dirn @Yield up} @SetContext {
The current direction is {@GetContext dirn}.
}
}
The object to the left of @@SetContext must be a @@Yield symbol whose
left parameter, the {@I key}, evaluates to a simple word, and whose
right parameter, the {@I value}, may be an arbitrary object.  Since
@@Yield has high precedence it will usually be necessary to enclose
non-trivial values in braces.  The effect is to associate the value
with the key in a symbol table throughout the right parameter of the
@@SetContext symbol, as part of the style information.  The value may
be retrieved anywhere in this region by invoking @@GetContext with the
key as its right parameter.
@PP
The value is evaluated using the style and environment where it occurs,
not where it is used.  In any case in most applications the value will
be a simple word, independent of any style and environment, used to
select a branch in a case expression, like this:
@ID @OneRow @Code @Verbatim {
{@GetContext dirn} @Case {
  up @Yield ...
  down @Yield ...
}
}
@@GetContext reports an error if there is no value associated with
its key in the current style.
@End @Section