The opposite of a GoTo statement. ----- '''History''' Encountered on a list of joke assembly language instructions around 1971 by AlistairCockburn. () Published in 1984. From the C-InterCal manual (): : The earliest known description of the COME FROM statement in the computing literature is in R. L. Clark, "A Linguistic contribution to GOTO-less programming," Commun. ACM 27 (1984), pp. 349-350, part of the famous April Fools issue of CACM. The subsequent rush by language designers to include the statement in their languages was underwhelming, one might even say nonexistent. It was therefore decided that COME FROM would be an appropriate addition to C-INTERCAL. In Donald Knuth's article '''Structured Programming with go to Statements''' Donald E. Knuth December 1974 ACM Computing Surveys (CSUR), Volume 6 Issue 4 he mentions the COME FROM statement, and refers to the article mentioned above as: Clark, R. Lawrence. "A linguistic contribution to GOTO-less programming," ''Datamation'' '''19''', 12 (December 1973), 62-63 Implemented by C-INTERCAL (). ----- It got a wonderful new semantic in Threaded InterCal! The original Intercal stated: It is an error for more than one COME FROM to refer to the same (label). This restriction was suspended in Threaded InterCal. ----- '''Is ComeFrom an ExceptionPattern?''' ''No'' These references to exceptions as implementing ComeFrom surprise me. I first encountered ComeFrom around 1971 on a list of joke assembler language instructions (along with "move and wrap core", and "move and wrap secretary"). I encountered it occasionally on such joke lists over the years, but never again until IvarJacobson brought it up again as a way of implementing his 'extension' mechanism in UseCases. Not everyone in the room seemed to recognize that he was simultaneously saying extensions are not implementable. At the risk of describing the painfully obvious, exceptions do not say where they are coming from. In fact, that is their purpose in life - to ''not'' say where they are coming from. ComeFrom has as its purpose in life exactly to state where it is coming from, although the named spot in the program is supposed to be blissfully unaware of it. So ComeFrom and ExceptionHandling are about as different as you could ask for, you sure couldn't implement exceptions with ComeFrom. I just couldn't stand to watch silently any longer. -- AlistairCockburn ''Very much so. "ComeTo" is probably a more accurate description of an exception handler. To raise an exception, you "JustSayGo."'' ComeAgain? Agreed. Don't know about all the roots of ComeFrom, but it was fairly well established (as a joke, at least) by the time I encountered it around 1977 (consistent with an INTERCAL origin, if that's taken as 1972; this is frankly the first I'd heard of INTERCAL as such). At Dartmouth (home of BASIC), this was used in structured-programming arguments: ComeFrom was asserted to be isomorphic to GoTo, in that the one could be mechanically translated to the other (it's true for many cases, but I haven't thought about this since so take it with a grain of salt). ''ComeFrom wasn't in the first version of INTERCAL; it is an addition in the C-INTERCAL version. Strangely enough, it turned out to be one of the most useful statements in INTERCAL...'' In any case, exceptions cannot be implemented with either ComeFrom or GoTo, not even non-local GoTo (by contrast, by the way, to a great many other programming constructs of greater political correctness). The equivalent flow control can be roughly implemented with label variables or setjmp/longjmp, but the mapping of that to a ComeFrom extension is not something I've thought about. -- JimPerry ----- '''Is there anything else like ComeFrom?''' Setting breakpoints in a debugger implements a '''dynamic''' ComeFrom. AspectOrientedProgramming and the Advice systems in some Lisps have been described as "structured ComeFrom." And then there's the inverted CASE statement. Kind of a "computed" COME FROM. ''As in "I'm here, so x must have a value of 7"? I've seen a lot code that effectively did that. Very nice when combined with multi-value switches. You get a holographic effect where the information about what the program is doing at any given line of code is spread throughout the entire program.'' You can do something like that in INTERCAL, since you can use the ABSTAIN/REINSTATE mechanism to enable or disable a specific COME FROM statement. There is now an CLC-INTERCAL compiler that has real computed COME FROM. You can COME FROM a variable, then assign to this variable... ''For example:'' PLEASE REINSTATE (9) (8) DO .1 <- #8 (9) PLEASE COME FROM (1009) DO ABSTAIN (9) (1000) DO COME FROM .1 ......... (1009) DO .1 <- #0 There is now a new proposed (: term called GoHere, which is followed by an expression describing conditions for its execution. Like '''GoHere When Finished''', Finished is Boolean true/false. Other examples at GoHere :) ---- '''What if 2 ComeFrom's reference the same location?''' In C-INTERCAL, it is an error if two COME FROM's point to the same location. But there's also a parallel INTERCAL, which does the RightThing and continues execution at ''both'' COME FROM's, in parallel. Note that this form of ComeFrom is strictly more powerful than GoTo. ''One might have a GoTo which took a list of destinations''. How about a COME FROM that takes several sources and implements a thread rendez-vous/termination? That might be an interesting extension to Parallel INTERCAL. ---- It is said that CallWithCurrentContinuation is a generalization of GoTo. Any ideas how a similar generalization of ComeFrom would look? I guess a (replace/call/cc cont value) function would be the functional counterpart. Its workings are simple - replace all references to cont (i.e. destructibly change the internal continuation state) so that it refers to the current continuation, then resume the original continuation in cont with the specified value. Dynamic redefinition of functions actually gives pretty much the same functionality, but limits the From's to function entry points. Then again, replace/call/cc is also limited in only accepting previously saved continuations. If you need to ComeFrom the middle of functions, modifying the function's source shouldn't be too hard though - decompile, insert GoTo, wrap in define, eval at its worst (although that solution uses GoTo, not ComeFrom). ----- Why can't we have an if statement that works the other way round? As an example: { x := x + 1; } else { x := x - 1; } if (x mod 2 == 0) This will increase x if it will be odd afterwards; it decreases x if this makes it even. ''I think you mean the other way round. What do you want to get when x = 2?'' Basically, what you seem to be looking for is something that will do: doFoo(); if !resultOkay { undoFoo(); doBar(); } If you want these kind of things, you should use the PrologLanguage, or perhaps the StructuredQueryLanguage. An example in both: doStuff :- doFoo, resultOkay. doStuff :- doBar. BEGIN SAVEPOINT beforeFoo; doFoo; IF NOT resultOkay THEN ROLLBACK TO SAVEPOINT beforeFoo; doBar; END IF; COMMIT; END; Of course, the rollback only applies to the contents of your tables. ''Don't be silly; SQL doesn't have a IF statements!'' {Actually, it does. See, for example, http://technet.microsoft.com/en-us/library/ms182717.aspx } ---- Both cases in the above example are equivalent... If (x mod 2 == 0), then (x + 1) and (x - 1) are both odd. The same logic holds if the value that x "would have" post-operationally is used. ''No, they're not equivalent. The 'PostCondition' is tested only once. I read the above as:'' x++; if (x mod 2 == 0) return x; else x--; // undoing the x++ x--; // the wanted effect return x; ''So the above should increase odd numbers, making them even, and would decrease even numbers, making them odd (which is not the claimed behaviour, BTW). Of course the simple example given can be redone with a regular if, but I think the requested feature is a valid one. Even though the PerlLanguage does have its post-ifs and post-unlesses, I don't think they work any different than the regular ones.'' ---- I just realized that ComeFrom looks an awful lot as a low-level version of the "cross-cutting" that products like AspectJ ( http://aspectj.org ) allow. In fact, one could do AspectOrientedProgramming in INTERCAL in this way: by adding a module that COME FROMs labels in the original program, the new module (aspect) can immediately enhance the program without textually changing it. -- StephanHouben It's interesting that you should say this, since Todd Proebsting (of Microsoft Research) dismissed AOP as "The Ultimate Come From" at the LL2 Conference at MIT. Actually, I hadn't grokked AOP until I thought about what he said, so it seems to me like a very useful comment. This is why (IMO) you really have to have really good editor support for AOP to be useful. -- Cullen J. O'Neill ----- A potential use for ComeFrom is in reversible computing (http://www.ai.mit.edu/~cvieri/reversible.html ). In a reversible instruction set it makes sense that the GoTo should have a symmetrical partner, the ComeFrom. GoTo''''''s are otherwise messy to handle in a reversible context because ''any'' instruction might serve as a target for a jump making it difficult to execute backwards. -- Dan Piponi ----- A useful extension is the DontComeFrom statement as in: if (x > 7) don't come from 100 ---- If ComeFrom is the pendant to GoTo then I wonder, how the pendants for GoSub (aka JumpSubRoutine) and ReturnFromSubRoutine might look like. One might call them ComeFromCaller (placed at the top of a 'subroutine') and ReturningFrom