COMEFROM
Encyclopedia
In computer program
ming, COMEFROM (or COME FROM) is an obscure control flow
structure used in some programming language
s, originally as a joke.
to
or otherwise concurrent execution as seen in Threaded Intercal
.
A simple example of a "
instructions (as 'CMFRM'). 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
On 1 April 2004, Richie Hindle published an implementation of both
and not being intended for serious use, the syntax is valid and the implementation fully works.
during debugging
. One implementation of FORTRAN
included it, under the name "
s have hardware support for breakpoints.
Some elements of aspect-oriented programming
have been compared to the COMEFROM statement.
In compilers using SSA, a phi node is essentially similar to a come from statement. It lists which basic block
s the current basic block could have been reached from and the associated value to use if it did.
In some reversible computing
assembly languages, the target of a
would be too difficult to read.
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 "
— the "
A fully runnable example in Python with the joke
This is an implementation in Ruby
of the Intercal COME FROM statement.
Some examples of the debug packet feature of the OS/360 Fortran G compiler:
In example 1, the values of SOLON, GFAR, and EWELL are examined as they were at the completion of statement 10. The AT statement indicates statement 11.
In example 2, all the values of STOCK are displayed when statement 35 is encountered.
In example 3, 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.
DSP
supports a
loops, that is essentially a
LCNTR=42;
DO x UNTIL LCE; /* COMEFROM x, unless the loop counter is zero */
F12=F0*F4, F8=F8+F12, F0=dm(I0,M3), F4=pm(I8,M9);
IF NZ dm(I2,M2) = F12;
IF ZF dm(I2,M2) = F1;
x: R2 = R3 + 76; /* the label "x" does not exist in the machine code */
Note that the loop termination condition, here specified as
A similar feature exists in Microchip dsPIC
's for (unnested) loops provided by the 'DO' assembly instruction. Its interruptible and trivial nesting goes up to one level with an additional 5 levels in software.
Serious programming contrivances involving ideas resembling COMEFROM:
Computer program
A computer program is a sequence of instructions written to perform a specified task with a computer. A computer requires programs to function, typically executing the program's instructions in a central processor. The program has an executable form that the computer can use directly to execute...
ming, COMEFROM (or COME FROM) is an obscure control flow
Control flow
In computer science, control flow refers to the order in which the individual statements, instructions, or function calls of an imperative or a declarative program are executed or evaluated....
structure used in some programming language
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....
s, originally as a joke.
COMEFROM
is roughly the opposite of GOTOGotogoto is a statement found in many computer programming languages. It is a combination of the English words go and to. It performs a one-way transfer of control to another line of code; in contrast a function call normally returns control...
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 parameterParameter (computer science)
In computer programming, a parameter is a special kind of variable, used in a subroutine to refer to one of the pieces of data provided as input to the subroutine. These pieces of data are called arguments...
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 COMEFROM
s referencing the same departure point may be invalid, be non-deterministic, be executed in some sort of defined priority, or even induce parallelParallel computing
Parallel computing is a form of computation in which many calculations are carried out simultaneously, operating on the principle that large problems can often be divided into smaller ones, which are then solved concurrently . There are several different forms of parallel computing: bit-level,...
or otherwise concurrent execution as seen in Threaded Intercal
INTERCAL
INTERCAL, a programming language parody, is an esoteric programming language that was created by Don Woods and James M. Lyon, two Princeton University students, in 1972. It satirizes aspects of the various programming languages at the time, as well as the proliferation of proposed language...
.
A simple example of a "
COMEFROM x
" statement is a labelLabel (programming language)
A label in a programming language is a sequence of characters that identifies a location within source code. In most languages labels take the form of an identifier, often followed by a punctuation character . In many high level programming languages the purpose of a label is to act as the...
x
(which does not need to be physically located anywhere near its corresponding COMEFROM
) that acts as a "trap door". When code execution reaches the label, control gets passed to the statement following the COMEFROM
. The effect of this is primarily to make debugging (and understanding the control flow of the program) extremely difficult, since there is no indication near the label that control will mysteriously jump to another point of the program.History
COMEFROM
was initially seen in lists of joke assembly languageAssembly language
An assembly language is a low-level programming language for computers, microprocessors, microcontrollers, and other programmable devices. It implements a symbolic representation of the machine codes and other constants needed to program a given CPU architecture...
instructions (as 'CMFRM'). It was elaborated upon in a Datamation
Datamation
Datamation was a print computer magazine published in the United States between 1957 and 1998. When first published it wasn't clear there would be a significant market for a computer magazine given how few computers there were...
article by R. Lawrence Clark in 1973, written in response to Edsger Dijkstra
Edsger Dijkstra
Edsger Wybe Dijkstra ; ) was a Dutch computer scientist. He received the 1972 Turing Award for fundamental contributions to developing programming languages, and was the Schlumberger Centennial Chair of Computer Sciences at The University of Texas at Austin from 1984 until 2000.Shortly before his...
's letter Go To Statement Considered Harmful. COMEFROM was eventually implemented in the C-INTERCAL variant of the esoteric programming language
Esoteric programming language
An esoteric programming language is a programming language designed as a test of the boundaries of computer programming language design, as a proof of concept, or as a joke...
INTERCAL
INTERCAL
INTERCAL, a programming language parody, is an esoteric programming language that was created by Don Woods and James M. Lyon, two Princeton University students, in 1972. It satirizes aspects of the various programming languages at the time, as well as the proliferation of proposed language...
along with the even more obscure 'computed
COMEFROM
'. There were also Fortran proposals for 'assigned COME FROM
' and a 'DONT
' keyword (to complement the existing 'DO
' loop).On 1 April 2004, Richie Hindle published an implementation of both
GOTO
and COMEFROM
for the Python programming language. Despite being released on April Fools' DayApril Fools' Day
April Fools' Day is celebrated in different countries around the world on April 1 every year. Sometimes referred to as All Fools' Day, April 1 is not a national holiday, but is widely recognized and celebrated as a day when many people play all kinds of jokes and foolishness...
and not being intended for serious use, the syntax is valid and the implementation fully works.
Practical uses
AlthoughCOMEFROM
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 well known use of a COMEFROM
-like construct is setting a breakpointBreakpoint
In software development, a breakpoint is an intentional stopping or pausing place in a program, put in place for debugging purposes. It is also sometimes simply referred to as a pause....
during debugging
Debugging
Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a computer program or a piece of electronic hardware, thus making it behave as expected. Debugging tends to be harder when various subsystems are tightly coupled, as changes in one may cause bugs to emerge...
. One implementation of FORTRAN
Fortran
Fortran is a general-purpose, procedural, imperative programming language that is especially suited to numeric computation and scientific computing...
included it, under the name "
AT
", as a debugging aid, with dire warnings against using it in production code. In addition, many modern CPUCentral processing unit
The central processing unit is the portion of a computer system that carries out the instructions of a computer program, to perform the basic arithmetical, logical, and input/output operations of the system. The CPU plays a role somewhat analogous to the brain in the computer. The term has been in...
s have hardware support for breakpoints.
Some elements of aspect-oriented programming
Aspect-oriented programming
In computing, aspect-oriented programming is a programming paradigm which aims to increase modularity by allowing the separation of cross-cutting concerns...
have been compared to the COMEFROM statement.
In compilers using SSA, a phi node is essentially similar to a come from statement. It lists which basic block
Basic block
In computing, a basic block is a portion of the code within a program with certain desirable properties that make it highly amenable to analysis. Compilers usually decompose programs into their basic blocks as a first step in the analysis process...
s the current basic block could have been reached from and the associated value to use if it did.
In some reversible computing
Reversible computing
Reversible computing is a model of computing where the computational process to some extent is reversible, i.e., time-invertible. A necessary condition for reversibility of a computational model is that the transition function mapping states to their successors at a given later time should be...
assembly languages, the target of a
GOTO
is always a COMEFROM
targeting the GOTO
.Examples
The following is an example of a program in a hypothetical BASIC dialect with "COMEFROM
" instead of "GOTO
". An actual example in INTERCALINTERCAL
INTERCAL, a programming language parody, is an esoteric programming language that was created by Don Woods and James M. Lyon, two Princeton University students, in 1972. It satirizes aspects of the various programming languages at the time, as well as the proliferation of proposed language...
would be too difficult to read.
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 NOPNOP
In computer science, NOP or NOOP is an assembly language instruction, sequence of programming language statements, or computer protocol command that effectively does nothing at all....
— 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:This is an implementation in Ruby
Ruby (programming language)
Ruby is a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. Ruby originated in Japan during the mid-1990s and was first developed and designed by Yukihiro "Matz" Matsumoto...
of the Intercal COME FROM statement.
Some examples of the debug packet feature of the OS/360 Fortran G compiler:
In example 1, the values of SOLON, GFAR, and EWELL are examined as they were at the completion of statement 10. The AT statement indicates statement 11.
In example 2, all the values of STOCK are displayed when statement 35 is encountered.
In example 3, 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.
Hardware implementation
The SHARCSuper Harvard Architecture Single-Chip Computer
The Super Harvard Architecture Single-Chip Computer is a high performance floating-point and fixed-point DSP from Analog Devices,...
DSP
Digital signal processor
A digital signal processor is a specialized microprocessor with an architecture optimized for the fast operational needs of digital signal processing.-Typical characteristics:...
supports a
DO..UNTIL
instruction, intended for do..whileDo while loop
In most computer programming languages, a do while loop, sometimes just called a do loop, is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition. Note though that unlike most languages, Fortran's do loop is actually analogous to the for loop.The...
loops, that is essentially a
COMEFROM
. Example:LCNTR=42;
DO x UNTIL LCE; /* COMEFROM x, unless the loop counter is zero */
F12=F0*F4, F8=F8+F12, F0=dm(I0,M3), F4=pm(I8,M9);
IF NZ dm(I2,M2) = F12;
IF ZF dm(I2,M2) = F1;
x: R2 = R3 + 76; /* the label "x" does not exist in the machine code */
Note that the loop termination condition, here specified as
LCE
(loop counter expired), can be set to other values including always-true and always-false. With an always-true condition, we have a genuine COMEFROM
. The hardware supports up to six simultaneously active COMEFROM
s.A similar feature exists in Microchip dsPIC
PIC microcontroller
PIC is a family of Harvard architecture microcontrollers made by Microchip Technology, derived from the PIC1650 originally developed by General Instrument's Microelectronics Division...
's for (unnested) loops provided by the 'DO' assembly instruction. Its interruptible and trivial nesting goes up to one level with an additional 5 levels in software.
See also
- F. X. ReidF. X. ReidF. X. Reid is the pen name of British computer science academic Mike W. Shields.Reid has been a long-time and contributor to the British Computer Society FACS Specialist Group newsletter FACS FACTS. He has been an enthusiast for the COMEFROM statement and an expert on its semantics...
, an expert on the semantics ofCOMEFROM
- Action at a distanceAction at a distance (computer science)Action at a distance is an anti-pattern in which behavior in one part of a program varies wildly based on difficult or impossible to identify operations in another part of the program....
- IntercalINTERCALINTERCAL, a programming language parody, is an esoteric programming language that was created by Don Woods and James M. Lyon, two Princeton University students, in 1972. It satirizes aspects of the various programming languages at the time, as well as the proliferation of proposed language...
Serious programming contrivances involving ideas resembling COMEFROM:
- Aspect-oriented programmingAspect-oriented programmingIn computing, aspect-oriented programming is a programming paradigm which aims to increase modularity by allowing the separation of cross-cutting concerns...
- ContinuationContinuationIn computer science and programming, a continuation is an abstract representation of the control state of a computer program. A continuation reifies the program control state, i.e...