6 Control

The inert data type is provided for use with control combiners. It consists of a single immutable value, having external representation #inert. The inert type is encapsulated.

— Applicative: inert? (inert? . objects)

The primitive type predicate for type inert. inert? returns true iff all the objects in objects are of type inert.

— Operative: $if ($if <test> <consequent> <alternative>)

The $if operative first evaluates <test> in the dynamic environment. If the result is not of type boolean, an error is signaled. If the result is true, <consequent> is then evaluated in the dynamic environment as a tail context. Otherwise, <alternative> is evaluated in the dynamic environment as a tail context.

— Operative: $sequence ($sequence . <objects>)

The $sequence operative evaluates the elements of the list <objects> in the dynamic environment, one at a time from left to right. If <objects> is a cyclic list, element evaluation continues indefinitely, with elements in the cycle being evaluated repeatedly. If <objects> is a nonempty finite list, its last element is evaluated as a tail context. If <objects> is the empty list, the result is inert.

— Operative: $cond ($cond . <clauses>)

<clauses> should be a list of clause expressions, each of the form (<test> . <body>), where body is a list of expressions.

The following equivalences define the behaviour of the $cond operative:

          ($cond) == #inert
          ($cond (<test> . <body>) . <clauses>) ==
            ($if <test> ($sequence . <body>) ($cond . <clauses>))
— Applicative: for-each (for-each applicative . lists)

lists must be a nonempty list of lists; if there are two or more, they should all be the same length. If lists is empty, or if all of its elements are not lists of the same length, an error is signaled.

for-each behaves identically to map, except that instead of accumulating and returning a list of the results of the element-wise applications, the results of the applications are discarded and the result returned by for-each is inert.

— Applicative: string-for-each (string-for-each applicative . strings)
— Applicative: vector-for-each (vector-for-each applicative. vectors)
— Applicative: bytevector-for-each (bytevector-for-each applicative . bytevectors)

stringsvectors, or bytevectors should be non-empty lists of the corresponding type and all elements should be of the same length.

These applicatives behave as for-each except that the list of elements passed to applicative are the n-th chars, objects, or uint8s of the strings, vectors or bytevectors passed as arguments.

SOURCE NOTE: These are taken from r7rs.

— Operative: $when ($when <test> . <body>)
— Operative: $unless ($unless <test> . <body>)

body should be a list of expressions.

These operatives behave as one-armed $ifs with an implicit $sequence, except that they always discard the last value and the result returned is inert.

So both $when, and $unless evaluate <test> in the dynamic environment. If the result is non boolean an error is signaled. In $when if the result is false and in $unless if the result is true, the expressions in <body> are not evaluated and an inert value is returned. Otherwise, the expressions in <body> are evaluated sequentially in the dynamic environment. If <body> is a non cyclic list, the last expression in <body> is evaluated in a special type of tail context, that, upon receiving a value discards it and returns an inert value instead. If <body> is a cyclic list, element evaluation continues indefinitely, with elements in the cycle being evaluated repeatedly. SOURCE NOTE: These are taken from r7rs.