an observation about united modes
Jose E. Marchesi
jemarch@gnu.org
Thu Jun 26 02:22:51 GMT 2025
Another advantage of structural type equivalence, and of being able to
express a full mode anywhere a mode specifier is expected, is shown in
the code below, from the same project of mine.
Basically it uses operators and priorities in order to implement a
ternary operator
x < y IN z
where x and y are symbols and z is an alphabet. Symbols only hold <
and > relationships with respect some given alphabet, so the trick is to
make
y IN z
to yield a "qualified symbol", which is a struct (y, z). Then the
operators < and > are defined to operate on a symbol x and a "qualified
symbol".
Qualified symbols can get created at any time using the operator IN.
{ Relational operators for qualified symbols.
IN builds a symbol qualified by some given alphabet, which then can
be used as the second operand of the operators < and >.
Note that IN shall have a higher priority than the relational
operators so that ternary expressions such as
a < b IN e1
can be written. }
prio IN = 6;
op IN = (Symbol s, Alphabet a) struct (Symbol s, Alphabet a):
(s, a);
op < = (Symbol s, struct (Symbol s, Alphabet a) qs) bool:
(pos_of_symbol_in_word (s, word of a of qs)
< pos_of_symbol_in_word (s of qs, word of a of qs));
op > = (Symbol s, struct (Symbol s, Alphabet a) qs) bool:
(pos_of_symbol_in_word (s, word of a of qs)
> pos_of_symbol_in_word (s of qs, word of a of qs));
More information about the Algol68
mailing list