Top Qs
Timeline
Chat
Perspective
COMEFROM
Programming language control flow statement; opposite of goto From Wikipedia, the free encyclopedia
Remove ads
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 (i.e. interpreter) 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.[citation needed]
COMEFROM was initially seen in lists of joke assembly language instructions (as 'CMFRM'). It was elaborated upon in a Datamation article by R. Lawrence Clark in 1973,[1] 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[2] for 'assigned COME FROM' and a 'DONT' statement (to complement the existing 'DO' loop).
Remove ads
Examples
Summarize
Perspective
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.[3]
The code below, which is actually runnable, uses this Python implementation.
from goto import comefrom, label
comefrom .repeat
name: str = raw_input("What is your name? ")
if name:
print(f"Hello, {name}")
label .repeat
print("Goodbye!")
Ruby
This is an implementation in Ruby of the Intercal COME FROM statement.
$come_from_labels = {}
def label(l)
if $come_from_labels[l]
$come_from_labels[l].call
end
end
def come_from(l)
callcc do |block|
$come_from_labels[l] = block
end
end
OS/360 Fortran G
In the OS/360 Fortran G compiler debug packet, the AT
statement acts like COMEFROM in that it hands the control flow over to the debug block – similar to a breakpoint.[4]
In the following code, the values of SOLON
, GFAR
, and EWELL
are examined as they were at the completion of statement 10. The AT
statement indicates statement 11.
INTEGER SOLON, GFAR, EWELL
.
.
.
10 SOLON = GFAR * SQRT(FLOAT(EWELL))
11 IF (SOLON) 40, 50, 60
.
.
.
DEBUG UNIT(3)
AT 11
DISPLAY GFAR, SOLON, EWELL
END
In the following code, the values of STOCK
are displayed when statement 35 is encountered.
DIMENSION STOCK(1000),OUT(1000)
.
.
.
DO 30 I=1, 1000
25 STOCK(I)=STOCK(I) - OUT(I)
30 CONTINUE
35 A = B + C
.
.
.
DEBUG UNIT(3)
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(3), 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
Remove ads
See also
- Action at a distance – Anti-pattern
- Continuation – Representation of the control state of a computer program
- Database trigger – Database code that executes after certain events on a table
- Event-driven programming – Computer programming paradigm
- F. X. Reid – an expert on the semantics of COMEFROM[5]
- Goto/From signal routing blocks in MATLAB Simulink
- Pointcut
- Observer pattern – Software design pattern based on an event-updated object with a list of dependents
- Webhook – Method of web development
Remove ads
References
External links
Wikiwand - on
Seamless Wikipedia browsing. On steroids.
Remove ads