COMEFROM

From Wikipedia, the free encyclopedia

In computer programming, COMEFROM (or COME FROM) is an obscure control flow structure used in some programming languages, primarily as a joke.

COMEFROM is roughly the opposite of GOTO in that it can take the execution state from any arbitrary point in code to a COMEFROM statement. The point in code where 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 used, multiple COMEFROMs referencing the same departure point may be invalid, be non-deterministic, be executed in some sort of defined priority, or even induce parallel or otherwise concurrent execution as seen in Threaded Intercal.

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 was also a proposal for 'assigned COMEFROM' for Fortran.

On 1st April 2004, Richie Hindle published an implementation of both GOTO and COMEFROM for the Python Programming language. At first sight experienced programmers might dismiss it as a crude April Fool joke inventing a bizarre syntax to persuade beginners that these statements exist in Python, but in fact it was a much more subtle joke on the experienced programmers as the syntax is valid and the implementation fully working (just not intended for use).

Contents

[edit] Practical uses

Although COMEFROM is syntactically and semantically valid, and capable of replacing GOTO in some programs, it is considerably more difficult to visualise in program design and actually implement in a programming language. The most practical known use of a COMEFROM-like structure is as a breakpoint during debugging. One implementation of FORTRAN included it, under the name "AT", as a debugging aid, with dire warnings against using it in production code. In addition, many modern CPUs have hardware support for breakpoints.

Some elements of aspect-oriented programming have been compared to the COMEFROM statement.[2]

[edit] Example

The following is an example of a program in a hypothetical BASIC dialect with "COMEFROM" instead of "GOTO". An actual example in INTERCAL would be too difficult to read.

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

The program (hypothetically) works by asking the user for their name, then greeting them with the same name, and continuing all over again. The instruction "REM" on line 40 is simply a noop — the "COMEFROM" statement on line 10 causes a branch back to that line when execution reaches line 40, regardless of its contents.

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

from goto import comefrom, label
comefrom .repeat
name = raw_input('what is your name? ')
if name:
    print "Hello",name
    label .repeat
print "Goodbye!"

[edit] See also

[edit] References

  1. ^ Clarke's Datamation Article
  2. ^ C2:ComeFrom

[edit] External links

In other languages