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.
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.
Below is an example program in a hypothetical dialect of BASIC with "COMEFROM" instead of "GOTO".
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:
This is an implementation in Ruby of the Intercal COME FROM statement.
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.
COMEFROM Serious programming techniques involving ideas reminiscent of COMEFROM:
Comments