Previous: , Up: Statements   [Index]


7.10 COME FROM and NEXT FROM

INTERCAL-72 C-INTERCAL CLC-INTERCAL J-INTERCAL
no see text see text see text

The COME FROM statement (incidentally also invented in 1972, but not in connection with INTERCAL) is the main control-flow command in CLC-INTERCAL (which deprecates NEXT), and one of two main control flow structures in other modern INTERCAL compilers. It takes either a label or an expression as its argument; these forms are noncomputed COME FROM and computed COME FROM.

Noncomputed COME FROM was implemented in version 0.5 of C-INTERCAL, but did not conform to modern-day semantics until version 0.7; it is available in every version of CLC-INTERCAL and J-INTERCAL. Computed COME FROM support is available in every version of CLC-INTERCAL and in C-INTERCAL from version 0.25 onwards, but not in J-INTERCAL; the variant NEXT FROM of COME FROM is available from CLC-INTERCAL version 1.-94.-8 and C-INTERCAL version 0.26 (both computed and noncomputed). C-INTERCAL and CLC-INTERCAL also have a from-gerund form of COME FROM and NEXT FROM, which was also implemented from CLC-INTERCAL version 1.-94.-8 and C-INTERCAL version 0.26.

The basic rule of COME FROM is that if a COME FROM statement references another statement, whenever that statement is reached, control flow will be transferred to the COME FROM after that statement finishes executing. (NEXT FROM is identical except that in addition to the COME FROM behaviour, the location immediately after the statement that was nexted from is saved on the NEXT stack, in much the same way as if the statement being nexted from was itself a NEXT.)

Here are examples of noncomputed, computed, and from-gerund COME FROM:

DO COME FROM (10)
DO COME FROM #2$'.1~#1'
DO COME FROM COMING FROM

(The last example is an infinite loop. If it said DO NEXT FROM NEXTING FROM, it would not be an infinite loop because the NEXT stack would overflow and cause an error. This also establishes the gerunds used for COME FROM and NEXT FROM.)

There are some things to be careful with involving COME FROM and NEXT FROM. First, if the statement come from or nexted from happens to be a NEXT, the NEXT doesn’t count as ’finishing executing’ until the NEXT stack entry created by the NEXT is RESUMEd to. In particular, this means that if FORGET is used to remove the entry, or a RESUME with a large argument resumes a lower entry, the COME FROM doesn’t steal execution at all.

Second, you may be wondering what happens if two COME FROMs or NEXT FROMs aim at the same line. In a non-multithreaded program (whether a program is multithreaded or not is determined by a compiler option for those compilers that support it), this is an error; but it is only an error if the statement that they both point to finishes running, and both COME FROMs or NEXT FROMs try to execute as a result (they might not if, for instance, one is abstained or has a double-oh-seven causing it not to run some of the time). If both COME FROMs or NEXT FROMs are noncomputed, however, a compiler can (but does not have to) give a compile time error if two COME FROMs or NEXT FROMs share a label, and so that situation should be avoided in portable code. (If it is wanted, one solution that works for C-INTERCAL and CLC-INTERCAL is to use computed COME FROMs or NEXT FROMs with a constant expression.)


Previous: , Up: Statements   [Index]