COMEFROM


In computer programming, COMEFROM is a control flow statement that causes control flow to jump to the statement after it when control reaches the point specified by the COMEFROM argument. The statement is intended to be the opposite of goto and is considered to be more a joke than serious computer science. Often the specified jump point is identified as a label. For example, COMEFROM x specifies that when control reaches the label x, then control continues at the statement after the COMEFROM.
A major difference with goto is that goto depends on the local structure of the code, while COMEFROM depends on the global structure. A goto statement transfers control when control reaches the statement, but COMEFROM requires the processor to scan for COMEFROM statements so that when control reaches any of the specified points, the processor can make the jump. The resulting logic tends to be difficult to understand since there is no indication near a jump point that control will in fact jump. One must study the entire program to see if any COMEFROM statements reference that point.
The semantics of a COMEFROM statement varies by programming language. In some languages, the jump occurs before the statement at the specified point is executed and in others the jump occurs after. Depending on the language, multiple COMEFROM statements that reference the same point may be invalid, non-deterministic, executed in some order, or induce parallel or otherwise concurrent processing as seen in Threaded Intercal.
COMEFROM was initially seen in lists of joke assembly language instructions. It was elaborated upon in a Datamation article by R. Lawrence Clark in 1973, 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 'assigned COME FROM' and a 'DONT' statement.

Examples

BASIC

The following code is for a hypothetical BASIC dialect with COMEFROM. It asks for a name, greets with the name, and repeats. Line 40 is the jump point specified by the COMEFROM, so when control reaches 40 it jumps to 10.

10 COMEFROM 40
20 INPUT "WHAT IS YOUR NAME? "; A$
30 PRINT "HELLO, "; A$
40 REM

Python

On 1 April 2004, Richie Hindle published an implementation of COMEFROM for Python that uses debugger hooks. Despite being released on April Fools' Day and not being intended for serious use, the syntax is valid and the implementation fully works.
The code below, which is actually runnable, uses this Python implementation.

from goto import comefrom, label
comefrom.repeat
name: str = raw_input
if name:
print
label.repeat
print

Ruby

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

$come_from_labels =
def label
if $come_from_labels
$come_from_labels.call
end
end
def come_from
callcc do |block|
$come_from_labels = block
end
end

OS/360 Fortran G

In the OS/360 Fortran G compiler debug packet, the statement acts like COMEFROM in that it hands the control flow over to the debug block similar to a breakpoint.
In the following code, the values of,, and are examined as they were at the completion of statement 10. The statement indicates statement 11.

INTEGER SOLON, GFAR, EWELL
.
.
.
10 SOLON = GFAR * SQRT
11 IF 40, 50, 60
.
.
.
DEBUG UNIT
AT 11
DISPLAY GFAR, SOLON, EWELL
END

In the following code, the values of are displayed when statement 35 is encountered.

DIMENSION STOCK,OUT
.
.
.
DO 30 I=1, 1000
25 STOCK=STOCK - OUT
30 CONTINUE
35 A = B + C
.
.
.
DEBUG UNIT
AT 35
DISPLAY STOCK
END

In the following code, tracing begins at statement 10, at statement 20, tracing stops while the loop is executed, and resumes after the loop. Tracing stops just before statement 30 is executed.

10 A = 1.5
12 L = 1
15 B = A + 1.5
20 DO 22 I = 1,5
.
.
.
22 CONTINUE
25 C = B + 3.16
30 D = C/2
STOP
.
.
.
DEBUG UNIT, TRACE
C DEBUG PACKET NUMBER 1
AT 10
TRACE ON
C DEBUG PACKET NUMBER 2
AT 20
TRACE OFF
DO 35 I = 1,3
.
.
.
35 CONTINUE
TRACE ON
C DEBUG PACKET NUMBER 3
AT 30
TRACE OFF
END