It was noted there thatprocedure shuffle(x) every !x :=: ?x return x end
x
may be a string, list, table, or
record but not a cset. The reason is that the operations !x
and ?x
do not apply to csets directly.x
is a cset its value is first converted to a string and
then the operation is applied. Consequently
writes the characters in the csetevery write(!x)
x
as expected. However the
implicit type conversion does not change the value of x
. The
expression above is therefore equivalent to
Similarlyevery write(!string(x))
This is much like!x :=: ?x is equivalent to !string(x) :=: ?string(x)
Neither argument of the exchange operation is a variable and a run-time error results.!"abc" :=: ?"abc"
1 to 5
is {1, 2, 3, 4, 5}. The results
that an expression actually produces depend on the context in which the
expression is used. For example
causes all the results forevery write(1 to 5)
1 to 5
to be produced, but in
only the first two results of(1 to 5) = 2
1 to 5
are produced.is simply the result sequence forexpr1 | expr2
expr1
followed by the result
sequence for expr2
(the concatenation of the result sequences).is the repeated concatenation of the result sequences for|expr
expr
.is {1, 2, 3, 4, 7, 8, 9, 10} and the result sequence for(1 to 4) | (7 to 10)
is {1, 1, 1, ... }. which is infinite. Similarly, the result sequence for|1
is {1, 2, 3, ... }.(i := 1) | |(i +:= 1)
false
. In control structures such as while-do
and if-then-else
, the empty result sequence also terminates
the result sequence for repeated alternation. Thus the result sequence for
is the sequence of lines from the input file. This sequence terminates when|read ()
read()
fails at the end of the file.which limitsexpr \ i
expr
to at most i
results. For example,
the result sequence for
is {1, 2, 3, ..., j}. assuming that the value of((i := 1) 1 I(i +:= 1)) \ j
j
is
a positive integer j. This provides an easy way of inspecting result
sequences; a typical test has the form
These observations on result sequences lead to the following exercises:every write(expr) \ 10
s
. For "abc"
the result sequence is {"a"
, "ab"
,
"abc"
, "bc"
, "c"
}.s
.(1)!&lcase || !&ucase
(2)(1 to 3) + (1 to 3)
(3)(1 to 3) \ (1 to 3)
(4) 1 to 5) = (4 to 9)
(5) 1 = |0