COMEFROM

Last updated

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 that it can take the execution state from any arbitrary point in code to a COMEFROM statement.

Contents

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.[ citation needed ]

A simple example of a "COMEFROM x" statement is a label 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. This may also be conditional, passing control only if a condition is satisfied, analogous to a GOTO within an IF statement. The primary difference from GOTO is that GOTO only depends on the local structure of the code, while COMEFROM depends on the global structure – a GOTO transfers control when it reaches a line with a GOTO statement, while COMEFROM requires scanning the entire program or scope to see if any COMEFROM statements are in scope for the line, and then verifying if a condition is hit. 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 line or label in question that control will mysteriously jump to another point of the program – one must study the entire program to see if any COMEFROM statements reference that line or label.

Debugger hooks can be used to implement a COMEFROM statement, as in the humorous Python goto module; [1] see below. This also can be implemented with the gcc feature "asm goto" as used by the Linux kernel configuration option CONFIG_JUMP_LABEL. A no-op has its location stored, to be replaced by a jump to an executable fragment that at its end returns to the instruction after the no-op.

History

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, [2] 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 [3] 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. [1] Despite being released on April Fools' Day and not being intended for serious use, the syntax is valid and the implementation fully works.

Practical uses

Examples

The following is an example of a program in a hypothetical BASIC dialect with "COMEFROM" instead of "GOTO".

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

This program (hypothetically) works by asking the user for their name, greeting them with the same name, and continuing all over again. The instruction "REM" on line 40 is simply a NOP (in this case, a REMark or comment) — 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:

fromgotoimportcomefrom,labelcomefrom.repeatname=raw_input('What is your name? ')ifname:print("Hello",name)label.repeatprint("Goodbye!")

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

$come_from_labels={}deflabel(l)if$come_from_labels[l]$come_from_labels[l].callendenddefcome_from(l)callccdo|block|$come_from_labels[l]=blockendend

OS/360 Fortran G

The OS/360 Fortran G compiler has a debug packet feature. Its "AT" statement is similar to COMEFROM in that it hands the control flow over to the debug block. Breakpoints in general are similar. [4]

INTEGER SOLON,GFAR,EWELL...10   SOLON=GFAR*SQRT(FLOAT(EWELL))11   IF(SOLON)40,50,60...DEBUGUNIT(3)AT11DISPLAYGFAR,SOLON,EWELLEND
DIMENSION STOCK(1000),OUT(1000)...DO 30I=1,100025   STOCK(I)=STOCK(I)-OUT(I)30   CONTINUE35   A=B+C...DEBUGUNIT(3)AT35DISPLAYSTOCKEND
10   A=1.512   L=115   B=A+1.520   DO 22I=1,5...22   CONTINUE25   C=B+3.1630   D=C/2STOP...DEBUGUNIT(3),TRACEC     DEBUG PACKET NUMBER 1AT10TRACEONC     DEBUG PACKET NUMBER 2AT20TRACEOFFDO 35I=1,3...35   CONTINUETRACEONC     DEBUG PACKET NUMBER 3AT30TRACEOFFEND

See also

Serious programming contrivances involving ideas resembling COMEFROM:

Related Research Articles

<span class="mw-page-title-main">GNU Debugger</span> Source-level debugger

The GNU Debugger (GDB) is a portable debugger that runs on many Unix-like systems and works for many programming languages, including Ada, Assembly, C, C++, D, Fortran, Go, Objective-C, OpenCL C, Modula-2, Pascal, Rust, and partially others.

PL/I is a procedural, imperative computer programming language initially developed by IBM. The PL/1 ANSI standard, X3.53-1976, was published in 1976. It is designed for scientific, engineering, business and system programming. It has been in continuous use by academic, commercial and industrial organizations since it was introduced in the 1960s.

Spaghetti code is a pejorative phrase for unstructured and difficult-to-maintain source code. Spaghetti code can be caused by several factors, such as volatile project requirements, lack of programming style rules, and software engineers with insufficient ability or experience.

In computer science, control flow is the order in which individual statements, instructions or function calls of an imperative program are executed or evaluated. The emphasis on explicit control flow distinguishes an imperative programming language from a declarative programming language.

<span class="mw-page-title-main">Debugger</span> Computer program used to test and debug other programs

A debugger or debugging tool is a computer program used to test and debug other programs. The main use of a debugger is to run the target program under controlled conditions that permit the programmer to track its execution and monitor changes in computer resources that may indicate malfunctioning code. Typical debugging facilities include the ability to run or halt the target program at specific points, display the contents of memory, CPU registers or storage devices, and modify memory or register contents in order to enter selected test data that might be a cause of faulty program execution.

An esoteric programming language is a programming language designed to test the boundaries of computer programming language design, as a proof of concept, as software art, as a hacking interface to another language, or as a joke. The use of the word esoteric distinguishes them from languages that working developers use to write software. The creators of most esolangs do not intend them to be used for mainstream programming, although some esoteric features, such as visuospatial syntax, have inspired practical applications in the arts. Such languages are often popular among hackers and hobbyists.

<span class="mw-page-title-main">Conditional (computer programming)</span> Control flow statement that executes code according to some condition(s)

In computer science, conditionals are programming language commands for handling decisions. Specifically, conditionals perform different computations or actions depending on whether a programmer-defined Boolean condition evaluates to true or false. In terms of control flow, the decision is always achieved by selectively altering the control flow based on some condition . Although dynamic dispatch is not usually classified as a conditional construct, it is another way to select between alternatives at runtime. Conditional statements are the checkpoints in the programe that determines behaviour according to situation.

In computing, a line number is a method used to specify a particular sequence of characters in a text file. The most common method of assigning numbers to lines is to assign every line a unique number, starting at 1 for the first line, and incrementing by 1 for each successive line.

A computer programming language is said to adhere to the off-side rule of syntax if blocks in that language are expressed by their indentation. The term was coined by Peter Landin, possibly as a pun on the offside rule in association football. This is contrasted with free-form languages, notably curly-bracket programming languages, where indentation has no computational meaning and indent style is only a matter of coding conventions and formatting. Off-side-rule languages are also described as having significant indentation.

<span class="mw-page-title-main">Breakpoint</span> Debugging method used in software development

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.

In most computer programming languages a do while loop is a control flow statement that executes a block of code and then either repeats the block or exits the loop depending on a given boolean condition.

In computer programming, a return statement causes execution to leave the current subroutine and resume at the point in the code immediately after the instruction which called the subroutine, known as its return address. The return address is saved by the calling routine, today usually on the process's call stack or in a register. Return statements in many programming languages allow a function to specify a return value to be passed back to the code that called the function.

In computer programming, a statement is a syntactic unit of an imperative programming language that expresses some action to be carried out. A program written in such a language is formed by a sequence of one or more statements. A statement may have internal components.

In computer science, a tail call is a subroutine call performed as the final action of a procedure. If the target of a tail is the same subroutine, the subroutine is said to be tail recursive, which is a special case of direct recursion. Tail recursion is particularly useful, and is often easy to optimize in implementations.

In computer programming languages, a switch statement is a type of selection control mechanism used to allow the value of a variable or expression to change the control flow of program execution via search and map.

In programming languages, a label 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 languages, the purpose of a label is to act as the destination of a GOTO statement. In assembly language, labels can be used anywhere an address can. Also in Pascal and its derived variations. Some languages, such as Fortran and BASIC, support numeric labels. Labels are also used to identify an entry point into a compiled sequence of statements.

<span class="mw-page-title-main">Goto</span> One-way control statement in computer programming

Goto is a statement found in many computer programming languages. It performs a one-way transfer of control to another line of code; in contrast a function call normally returns control. The jumped-to locations are usually identified using labels, though some languages use line numbers. At the machine code level, a goto is a form of branch or jump statement, in some cases combined with a stack adjustment. Many languages support the goto statement, and many do not.

In computer programming and software development, debugging is the process of finding and resolving bugs within computer programs, software, or systems.

Tracing just-in-time compilation is a technique used by virtual machines to optimize the execution of a program at runtime. This is done by recording a linear sequence of frequently executed operations, compiling them to native machine code and executing them. This is opposed to traditional just-in-time (JIT) compilers that work on a per-method basis.

In computing, Java bytecode is the bytecode-structured instruction set of the Java virtual machine (JVM), a virtual machine that enables a computer to run programs written in the Java programming language and several other programming languages, see List of JVM languages.

References

  1. 1 2 Hindle, Richie (1 April 2004), goto for Python, Entrian.
  2. Clarke, Lawrence, "We don't know where to GOTO if we don't know where we've COME FROM. This linguistic innovation lives up to all expectations.", Datamation (article), archived from the original on 2018-07-16, retrieved 2004-09-24.
  3. Modell, Howard; Slater, William (April 1978). "Structured programming considered harmful". ACM SIGPLAN Notices. 13 (4): 76–79. doi: 10.1145/953411.953418 . Retrieved 18 July 2014.
  4. IBM System/360 and System/370 Fortran IV Language, GC28-6515-10, May 1974
  5. F. X. Reid, On the Formal Semantics of the COMEFROM Statement. FACS FACTS, Issue 2006-1, pages 18–20, March 2006.