COMEFROM: The Inverse of the GOTO Statement

Lecture



In computer programming, COMEFROM (or COME FROM) is an obscure control flow structure used in some programming languages, originally as a joke. COMEFROM is the inverse of GOTO in the sense that it can take the execution state from any arbitrary point in the code to the COMEFROM statement.

The point in the code at which the state transfer happens is usually given as a parameter to COMEFROM. Whether the transfer happens before or after the instruction at the specified transfer point depends on the language used. Depending on the language, multiple COMEFROMs referring to the same departure point may be invalid, non-deterministic, executed with some defined priority, or even cause parallel or otherwise concurrent execution, as seen in Threaded Intercal. [ citation needed ]

A simple example of a "COMEFROM x" statement is a label x (which does not necessarily have to be physically located anywhere near its corresponding COMEFROM) that acts as a "trap door". When code execution reaches the label, control is transferred to the statement following the COMEFROM. This can also be conditional, transferring control only if a condition is satisfied, similar to a GOTO in an IF statement. The main difference from GOTO is that GOTO depends only on the local structure of the code, whereas COMEFROM depends on the global structure - GOTO transfers control when it reaches the line containing the GOTO statement, whereas COMEFROM requires scanning the entire program or scope to see whether any COMEFROM statements fall within the scope of the line, and then checking whether the condition is met. The effect of this is, above all, to make debugging (and understanding the program's control flow) extremely difficult, since there is nothing near the line or label in question to indicate that control will mysteriously jump to another point in the program - one has to examine the entire program to see whether any COMEFROM statements refer to that line or label.

Debugger hooks can be used to implement a COMEFROM statement, as in the humorous goto module for Python; see below. It can also be implemented with the gcc "asm goto" feature, which is used by the Linux kernel configuration option CONFIG_JUMP_LABEL. A no-op position is recorded and is replaced with a jump to an executable fragment, which at the end returns to the instruction after the no-op.

History

COMEFROM was originally seen in lists of assembly language instructions (as "CMFRM"). It was developed in a 1973 Datamation article by R. Lawrence Clark, , written in response to Edsger Dijkstra's letter "Go To Statement Considered Harmful". COMEFROM was eventually implemented in the C-INTERCAL variant of the esoteric programming language INTERCAL, along with the even more obscure "computed COMEFROM". There were also Fortran proposals for an "assigned COME FROM" and a "DONT" keyword (to complement the existing DO loop).

On April 1, 2004, Richie Hindle published an implementation of both GOTO and COMEFROM for the Python programming language. Even though it was released on April Fools' Day and is not intended for serious use, the syntax is valid and the implementation is fully working.

Practical use

Examples

Below is an example program in a hypothetical dialect of BASIC with "COMEFROM" instead of "GOTO".

COMEFROM: The Inverse of the GOTO Statement
 

This program (hypothetically) works by asking the user for their name, greeting them by that name, and repeating the whole thing again. The "REM" instruction on line 40 is just a NOP (in this case, a comment) - the "COMEFROM" statement on line 10 causes a jump back to that line when execution reaches line 40, regardless of its content.

A fully executable example in Python with the goto joke module installed (which uses debugger hooks to control program execution) looks like this:

 COMEFROM: The Inverse of the GOTO Statement

This is an implementation in Ruby of the Intercal COME FROM statement.

 
COMEFROM: The Inverse of the GOTO Statement

OS / 360 Fortran G

The OS / 360 Fortran G compiler has a debug package feature. Its "AT" statement is similar to COMEFROM in that it transfers the flow of control to a debug block. Breakpoints are similar in general.

  • Example 1: the values of SOLON, GFAR and EWELL are checked as they were when statement 10 completed. The AT statement points to statement 11.
    COMEFROM: The Inverse of the GOTO Statement    
     
        
     
  • Example 2: all values of STOCK are displayed when statement 35 is encountered.
  COMEFROM: The Inverse of the GOTO Statement
      
     
  • Example 3: tracing starts at statement 10; at statement 20, tracing stops for the duration of the loop and resumes after the loop. Tracing ends just before statement 30 is executed.
COMEFROM: The Inverse of the GOTO Statement
    

See also

  • FX Reid, an expert on the semantics of COMEFROM
  • Action at a distance
  • Intercal

Serious programming techniques involving ideas reminiscent of COMEFROM:

  • Pointcut in aspect-oriented programming
  • Continuation ( Continuation ) [[b8294]]
  • Database triggers
  • Goto / From signal routing blocks in MATLAB Simulink

See also

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Algorithmization and programming. Structural programming. C language"

Terms: Algorithmization and programming. Structural programming. C language