The Churn command either initiates a Sequence, steps one iteration through a Sequence, or terminates a Sequence. Usually sequences are invoked using the Do-Sequence command. Occasionally you will want to use the Churn command to intiate or advance a sequence stepwise.
When initiating a Sequence with the Churn command no element is returned. The Sequence procedure runs up to the first Yield command. It could also reach a Return command in which case the Sequence immediately terminates. The Sequence With clause ("It") refers the state of the Sequence to advance. The caller can detect an empty Sequence afterwards with the "It`Open" condition.
CHURN from Variable with It CHURN from Sequence( [Argument, ...] ) with It
Where multiple nested Sequnces are active at the same time a different With variable will be needed. Also within the same procedure a different With variable needs to be used when invoking different sequences. However, if the same Sequence procedure is repeatedly run from the same pocedure then the same iterator variable can be used. With repeated use the prior Sequence is terminated when the Sequence is restarted.
Once a Sequence has been intiated you can use the Churn command to advance one iteration and return a value.
CHURN [@]Result from It CHURN [@]Result from Variable with It CHURN [@]Result from Sequence( [Argument, ...] ) with It
The next element must be present or a fault will be raised. It is the caller's responsibility to know that the Sequence has not been terminated and will always return a result. You can test to see if a sequence is still active by checking the sequence iterator variable (It`open). Alternatively, the length of the sequence is often known such as when iterating over a container of a known size.
CHURN from Read.Line( Path ) with It: Begin individual calls. DO while It`open: DO WHILE more in the sequence, CHURN Line from It; Get the next line. - CHURN from Read.Line( Path ) with It: Restart individual calls. DO until It`closed: DO UNTIL no more in the sequence, CHURN Line from It; Get the next line. -
To terminate a Sequence code the 'end' keyword on the Churn command. When followed by the iteration variable then that Sequence is terminated.
CHURN end It; Explicitly end a sequence.
Within a Do-Sequence loop you can omit the iteration variable to terminate the Sequence. Note that when exiting or unwinding a procedure any active Sequences will be terminated.
DO Line from Read.Line( Path ): DO over lines of text, IF Line: IF there is some text, PRINT Line; Print it out. ELSE: ELSE an empty line, CHURN end; Terminate the Sequence. - .