Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
COMEFROM
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Programming language control flow structure}} In [[computer program]]ming, '''COMEFROM''' (or '''COME FROM''') is an obscure [[control flow]] structure used in some [[programming language]]s, originally as a joke. <code>COMEFROM</code> is the inverse of <code>[[GOTO]]</code> in that it can take the execution state from any arbitrary point in code to a <code>COMEFROM</code> statement. The point in code where the state transfer happens is usually given as a [[parameter (computer science)|parameter]] to <code>COMEFROM</code>. 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 <code>COMEFROM</code>s referencing the same departure point may be invalid, be non-deterministic, be executed in some sort of defined priority, or even induce [[parallel computing|parallel]] or otherwise [[concurrent computing|concurrent]] execution as seen in [[INTERCAL|Threaded Intercal]].{{cn|date=September 2019}} A simple example of a "<code>COMEFROM x</code>" statement is a [[label (programming language)|label]] <code>x</code> (which does not need to be physically located anywhere near its corresponding <code>COMEFROM</code>) that acts as a "trap door". When code execution reaches the label, control gets passed to the statement following the <code>COMEFROM</code>. 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;<ref name=":0" /> see [[COMEFROM#PythonGoto|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== <code>COMEFROM</code> 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,<ref>{{Citation |url= http://www.fortran.com/fortran/come_from.html |last= Clarke |first= Lawrence |author-link= R. Lawrence Clark |title= 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. |journal= [[Datamation]] |type= article |access-date= 2004-09-24 |archive-url= https://web.archive.org/web/20180716171336/http://www.fortran.com/fortran/come_from.html |archive-date= 2018-07-16 |url-status= dead }}.</ref> 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 <code>COMEFROM</code>'. There were also [[Fortran]] proposals<ref>{{Cite journal |url= http://www.modell.com/Magery/SPharmful.html |last= Modell |first= Howard |last2= Slater |first2= William |title= Structured programming considered harmful |date= April 1978 |journal= ACM SIGPLAN Notices |volume=13 |issue= 4 |pages= 76β79 |doi= 10.1145/953411.953418 |access-date= 18 July 2014|doi-access= free }}</ref> for 'assigned <code>COME FROM</code>' and a '<code>DONT</code>' keyword (to complement the existing '<code>DO</code>' loop). {{Anchor|PythonGoto}}On 1 April 2004, [[Richie Hindle]] published an implementation of both <code>GOTO</code> and <code>COMEFROM</code> for the [[Python programming language]].<ref name=":0">{{Citation|last=Hindle|first=Richie|title=goto for Python|date=1 April 2004|url=http://entrian.com/goto/|publisher=Entrian}}.</ref> 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 programming language|BASIC]] dialect with "<code>COMEFROM</code>" instead of "<code>GOTO</code>". <syntaxhighlight lang="qbasic"> 10 COMEFROM 40 20 INPUT "WHAT IS YOUR NAME? "; A$ 30 PRINT "HELLO, "; A$ 40 REM </syntaxhighlight> This program (hypothetically) works by asking the user for their name, greeting them with the same name, and continuing all over again. The instruction "<code>REM</code>" on line 40 is simply a [[NOP (code)|NOP]] (in this case, a REMark or [[Comment (computer programming)|comment]]) β the "<code>COMEFROM</code>" 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 <code>'''goto'''</code> module installed (which uses debugger hooks to control program execution) looks like this: <syntaxhighlight lang="python"> from goto import comefrom, label comefrom .repeat name = raw_input("What is your name? ") if name: print("Hello", name) label .repeat print("Goodbye!") </syntaxhighlight> This is an implementation in [[Ruby (programming language)|Ruby]] of the Intercal COME FROM statement. <syntaxhighlight lang="ruby"> $come_from_labels = {} def label(l) if $come_from_labels[l] $come_from_labels[l].call end end def come_from(l) callcc do |block| $come_from_labels[l] = block end end </syntaxhighlight> === 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]]s in general are similar.<ref>IBM System/360 and System/370 Fortran IV Language, GC28-6515-10, May 1974</ref> * 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. <syntaxhighlight lang="fortranfixed"> 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 </syntaxhighlight> * Example 2: all the values of STOCK are displayed when statement 35 is encountered. <syntaxhighlight lang="fortranfixed"> 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 </syntaxhighlight> * 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. <syntaxhighlight lang="fortranfixed"> 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 </syntaxhighlight> ==See also== *[[F. X. Reid]], an expert on the semantics of <code>COMEFROM</code><ref>F. X. Reid, On the Formal Semantics of the COMEFROM Statement. [https://www.bcs.org/media/5044/issue-2006-1-march-2006.pdf ''FACS FACTS'', Issue 2006-1], pages 18β20, March 2006.</ref> *[[Action at a distance (computer science)|Action at a distance]] *[[INTERCAL]] Serious programming contrivances involving ideas resembling COMEFROM: *[[Pointcut]] in [[aspect-oriented programming]] *[[Continuation]] *[[Database trigger]]s *[[Observer pattern]] *[[Event-driven programming]] *[[Webhook]] *Goto/From signal routing blocks in [[MATLAB]] Simulink ==References== {{reflist}} ==External links== *[http://c2.com/cgi/wiki?ComeFrom COMEFROM Information Page] *[https://web.archive.org/web/20180716171336/http://www.fortran.com/fortran/come_from.html Datamation Article] *[https://web.archive.org/web/20121022080527/http://homepage.ntlworld.com/brook.street/funny/pdp11.htm Joke Assembler Instruction List Including CMFRM] *[https://metacpan.org/module/Acme::ComeFrom comefrom support for Perl] {{DEFAULTSORT:Comefrom}} [[Category:Computer humour]] [[Category:Control flow]] [[Category:Articles with example Python (programming language) code]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Anchor
(
edit
)
Template:Citation
(
edit
)
Template:Cite journal
(
edit
)
Template:Cn
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)