control.texi (4319B)
1 @c -*-texinfo-*- 2 @setfilename ../src/control 3 4 @node Control, Pairs and lists, Symbols, Top 5 @comment node-name, next, previous, up 6 7 @chapter Control 8 @cindex control 9 @cindex inert 10 The inert data type is provided for use with control combiners. It 11 consists of a single immutable value, having external representation 12 @code{#inert}. The inert type is encapsulated. 13 14 @deffn Applicative inert? (inert? . objects) 15 The primitive type predicate for type inert. @code{inert?} 16 returns true iff all the objects in @code{objects} are of type inert. 17 @end deffn 18 19 @deffn Operative $if ($if <test> <consequent> <alternative>) 20 The @code{$if} operative first evaluates @code{<test>} in the 21 dynamic environment. If the result is not of type boolean, an error 22 is signaled. If the result is true, @code{<consequent>} is then 23 @c TODO add xref to tail context 24 evaluated in the dynamic environment as a tail context. Otherwise, 25 @code{<alternative>} is evaluated in the dynamic environment as a tail 26 context. 27 @end deffn 28 29 @deffn Operative $sequence ($sequence . <objects>) 30 The @code{$sequence} operative evaluates the elements of the list 31 @code{<objects>} in the dynamic environment, one at a time from left 32 to right. If @code{<objects>} is a cyclic list, element evaluation 33 continues indefinitely, with elements in the cycle being evaluated 34 repeatedly. If @code{<objects>} is a nonempty finite list, its last 35 @c TODO add xref for tail context. 36 element is evaluated as a tail context. If @code{<objects>} is the 37 empty list, the result is inert. 38 @end deffn 39 40 @deffn Operative $cond ($cond . <clauses>) 41 @code{<clauses>} should be a list of clause expressions, each of the 42 form @code{(<test> . <body>)}, where body is a list of expressions. 43 44 The following equivalences define 45 the behaviour of the @code{$cond} operative: 46 @example 47 ($cond) @equiv{} #inert 48 ($cond (<test> . <body>) . <clauses>) @equiv{} 49 ($if <test> ($sequence . <body>) ($cond . <clauses>)) 50 @end example 51 @end deffn 52 53 @deffn Applicative for-each (for-each applicative . lists) 54 @code{lists} must be a nonempty list of lists; if there are two or 55 more, they should all be the same length. If lists is empty, or if all 56 of its elements are not lists of the same length, an error is 57 signaled. 58 59 @c TODO add xref to map 60 @code{for-each} behaves identically to @code{map}, except that instead 61 of accumulating and returning a list of the results of the 62 element-wise applications, the results of the applications are 63 discarded and the result returned by @code{for-each} is inert. 64 @end deffn 65 66 @deffn Applicative string-for-each (string-for-each applicative . strings) 67 @deffnx Applicative vector-for-each (vector-for-each applicative. vectors) 68 @deffnx Applicative bytevector-for-each (bytevector-for-each applicative . bytevectors) 69 @code{strings}, @code{vectors}, or @code{bytevectors} should be 70 non-empty lists of the corresponding type and all elements should be 71 of the same length. 72 73 These applicatives behave as @code{for-each} except that the list of 74 elements passed to @code{applicative} are the n-th chars, objects, or 75 uint8s of the strings, vectors or bytevectors passed as arguments. 76 77 SOURCE NOTE: These are taken from r7rs. 78 @end deffn 79 80 @deffn Operative $when ($when <test> . <body>) 81 @deffnx Operative $unless ($unless <test> . <body>) 82 @code{body} should be a list of expressions. 83 84 These operatives behave as one-armed @code{$if}s with an implicit 85 @code{$sequence}, except that they always discard the last value and 86 the result returned is inert. 87 88 So both @code{$when}, and @code{$unless} evaluate @code{<test>} in the 89 dynamic environment. If the result is non boolean an error is 90 signaled. In @code{$when} if the result is false and in 91 @code{$unless} if the result is true, the expressions in @code{<body>} 92 are not evaluated and an inert value is returned. Otherwise, the 93 expressions in @code{<body>} are evaluated sequentially in the dynamic 94 environment. If @code{<body>} is a non cyclic list, the last 95 expression in @code{<body>} is evaluated in a special type of tail 96 context, that, upon receiving a value discards it and returns an inert 97 value instead. If @code{<body>} is a cyclic list, element evaluation 98 continues indefinitely, with elements in the cycle being evaluated 99 repeatedly. 100 @c TODO xref tail-context 101 SOURCE NOTE: These are taken from r7rs. 102 @end deffn