• Handouts
repeat-statement consists of
the keyword repeat, one or more statements, the keyword until, and a Boolean expression. Any two otherwise adjacent statements
between repeat and until must be separated by a semicolon.
Taking the <statement> and <Boolean expression> categories as
given, write a description of the syntax of repeat-statements in
Pascal in extended Backus-Naur form.
let-expression in the CHECKED language of section 7.1.
when-expression, with the syntax
when <expression> <expression>
A when-expression has the value of its second subexpression if the
value of its first subexpression is the Boolean value true;
otherwise, the value of the when-expression is the Boolean value
false.
Which, if either, of the subexpressions of a when-expression are in
operand position? Which, if either, are in tail position?
continuation data type that would be needed
in order to add when-expressions to the continuation-passing
interpreter for LETREC developed there.
letrec iterate(n) = proc (f)
proc (b)
if zero?(n)
then b
else (f (((iterate -(n, 1)) f) b))
in (((iterate 5) proc(n) -(n, -(0, n))) 7)
(1) In SNOBOL4, there is a predefined identifier OUTPUT that is
treated as a write-only reference. Attempting to determine the value of
OUTPUT is a run-time error; however, OUTPUT can be used in
any other context that requires a reference, such as the left-hand side of
an assignment. When a value is assigned to OUTPUT, it is coerced to
the STRING data type (if this is not possible, a run-time error
occurs) and the result is written to standard output, usually the terminal
monitor. For example, the SNOBOL4 equivalent of Scheme's
(display "x is equal to ") (display x) (newline)
where the value of x is an integer, would be
OUTPUT = "x is equal to " x
(In SNOBOL4, the blank is used as a string-concatenation operator.)
(2) In the C++ programming language, there is a binary operator <<.
When the left operand is a text stream (i.e., what Scheme calls an output
port connected to text file), the << operator signifies that the
value of the right operand is to be output to that stream. The operator is
multiply overloaded; for every simple C++ data type, there is a different
<< procedure to output a value of that type, and the compiler
determines which one to use by determining the type of the second operand.
(Actually, the << operator is overloaded even further; when an
expression of integer type appears as left operand, << signifies a
left arithmetic shift, with the number of bit positions to be shifted
determined by the value of the second operand.)
In C++, the output statement given as an example above would be written
cout << "x is equal to " << x << "\n";
where cout is the standard output stream and "\n" is a string
containing only a line terminator.
(3) For every unstructured data type, and for strings, Modula-2 supplies a
special procedure to output a value of that data type: WriteString
to output a string, WriteReal to output a real number, and so on, as
well as WriteLn to output a line terminator. In Modula-2, the
example would be coded as
WriteString ("x is equal to ");
WriteInt (x, 1);
WriteLn
(If you like, you may suggest minor modifications in one of these schemes before announcing your preference for it.)