Comefrom
   HOME

TheInfoList



OR:

In
computer program A computer program is a sequence or set of instructions in a programming language for a computer to Execution (computing), execute. It is one component of software, which also includes software documentation, documentation and other intangibl ...
ming, COMEFROM (or COME FROM) is an obscure
control flow In computer science, control flow (or flow of control) 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 '' ...
structure used in some
programming language A programming language is a system of notation for writing computer programs. Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
s, 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. The point in code where the state transfer happens is usually given as a
parameter A parameter (), generally, is any characteristic that can help in defining or classifying a particular system (meaning an event, project, object, situation, etc.). That is, a parameter is an element of a system that is useful, or critical, when ...
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. A simple example of a "COMEFROM x" statement is a
label A label (as distinct from signage) is a piece of paper, plastic film, cloth, metal, or other material affixed to a container or product. Labels are most often affixed to packaging and containers using an adhesive, or sewing when affix ...
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; see
below Below may refer to: *Earth *Ground (disambiguation) *Soil *Floor * Bottom (disambiguation) *Less than *Temperatures below freezing *Hell or underworld People with the surname * Ernst von Below (1863–1955), German World War I general * Fred Belo ...
. This also can be implemented with the gcc feature "asm goto" as used by the
Linux kernel The Linux kernel is a Free and open-source software, free and open source Unix-like kernel (operating system), kernel that is used in many computer systems worldwide. The kernel was created by Linus Torvalds in 1991 and was soon adopted as the k ...
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 In computing, assembly language (alternatively assembler language or symbolic machine code), often referred to simply as assembly and commonly abbreviated as ASM or asm, is any low-level programming language with a very strong correspondence bet ...
instructions (as 'CMFRM'). It was elaborated upon in a
Datamation ''Datamation'' is a computer magazine that was published in print form in the United States between 1957 and 1998,
article by R. Lawrence Clark in 1973, written in response to
Edsger Dijkstra Edsger Wybe Dijkstra ( ; ; 11 May 1930 – 6 August 2002) was a Dutch computer scientist, programmer, software engineer, mathematician, and science essayist. Born in Rotterdam in the Netherlands, Dijkstra studied mathematics and physics and the ...
's letter '' Go To Statement Considered Harmful''. COMEFROM was eventually implemented in the C-INTERCAL variant of the
esoteric programming language An esoteric programming language (sometimes shortened to esolang) 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 ...
INTERCAL The Compiler Language With No Pronounceable Acronym (INTERCAL) is an esoteric programming language that was created as a parody by Don Woods (programmer), Don Woods and , two Princeton University students, in 1972. It satirizes aspects of the v ...
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 Python is a high-level, general-purpose programming language. Its design philosophy emphasizes code readability with the use of significant indentation. Python is dynamically type-checked and garbage-collected. It supports multiple prog ...
.. Despite being released on
April Fools' Day April Fools' Day or April Fool's Day (rarely called All Fools' Day) is an annual custom on the 1st of April consisting of practical jokes, hoaxes, and pranks. Jokesters often expose their actions by shouting "April Fool " at the recipient. ...
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 Basic or BASIC may refer to: Science and technology * BASIC, a computer programming language * Basic (chemistry), having the properties of a base * Basic access authentication, in HTTP Entertainment * Basic (film), ''Basic'' (film), a 2003 film ...
dialect with "COMEFROM" instead of "GOTO". 10 COMEFROM 40 20 INPUT "WHAT IS YOUR NAME? "; A$ 30 PRINT "HELLO, "; A$ 40 REM 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: from goto import comefrom, label comefrom .repeat name = raw_input("What is your name? ") if name: print("Hello", name) label .repeat print("Goodbye!") This is an implementation in
Ruby Ruby is a pinkish-red-to-blood-red-colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sapph ...
of the Intercal COME FROM statement. $come_from_labels = def label(l) if $come_from_labels $come_from_labels call end end def come_from(l) callcc do , block, $come_from_labels = block end end


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.
Breakpoint In software development, a breakpoint is an intentional stopping or pausing place in a computer program, program, put in place for debugging purposes. It is also sometimes simply referred to as a pause. More generally, a breakpoint is a means o ...
s in general are similar. * 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. 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 * Example 2: all 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 * 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. 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


See also

*
F. X. Reid Michael ("Mike") William Shields (20 January 1950 – 24 September 2023) was a British computer scientist. Overview Mike Shields undertook research on concurrent systems with Peter E. Lauer at the University of Newcastle upon Tyne in the late ...
, an expert on the semantics of COMEFROMF. X. Reid, On the Formal Semantics of the COMEFROM Statement
''FACS FACTS'', Issue 2006-1
pages 18–20, March 2006.
*
Action at a distance Action at a distance is the concept in physics that an object's motion (physics), motion can be affected by another object without the two being in Contact mechanics, physical contact; that is, it is the concept of the non-local interaction of ob ...
*
INTERCAL The Compiler Language With No Pronounceable Acronym (INTERCAL) is an esoteric programming language that was created as a parody by Don Woods (programmer), Don Woods and , two Princeton University students, in 1972. It satirizes aspects of the v ...
Serious programming contrivances involving ideas resembling COMEFROM: * Pointcut in
aspect-oriented programming In computing, aspect-oriented programming (AOP) is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns. It does so by adding behavior to existing code (an advice) ''without'' modifying t ...
*
Continuation In computer science, a continuation is an abstract representation of the control state of a computer program. A continuation implements ( reifies) the program control state, i.e. the continuation is a data structure that represents the computat ...
*
Database trigger A database trigger is procedural code that is automatically executed in response to certain Event (computing), events on a particular Table (database), table or View (database), view in a database. The trigger is mostly used for maintaining the Dat ...
s *
Observer pattern In software design and software engineering, the observer pattern is a software design pattern in which an object, called the ''subject'' (also known as ''event source'' or ''event stream''), maintains a list of its dependents, called observers (a ...
*
Event-driven programming In computer programming, event-driven programming is a programming paradigm in which the Control flow, flow of the program is determined by external Event (computing), events. User interface, UI events from computer mouse, mice, computer keyboard, ...
*
Webhook In web development, a webhook is a method of augmenting or altering the behavior of a web page or web application with custom callbacks. These callbacks may be maintained, modified, and managed by third-party users who need not be affiliated with ...
*Goto/From signal routing blocks in
MATLAB MATLAB (an abbreviation of "MATrix LABoratory") is a proprietary multi-paradigm programming language and numeric computing environment developed by MathWorks. MATLAB allows matrix manipulations, plotting of functions and data, implementat ...
Simulink


References


External links


COMEFROM Information Pagecomefrom support for Perl
{{DEFAULTSORT:Comefrom Computer humour Control flow Articles with example Python (programming language) code