Comefrom

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.

R. Lawrence Clark

Comefrom is a ludicriously powerful flow-control innovation that obviates the need for those sirens of structured programming, if then and while.

Bare comefrom statements are eligible for jumps from any blank line, provided they are in a scope visible from the blank line.

Comefrom also comes in two varieties, the qualified comefrom [blockname] and conditional comefrom if [condition]. A statement may be both qualified and conditional, that is, in the form comefrom [blockname] if [condition].

Multiple comefrom dispatch

One of the first things that people think when they encounter comefrom is, “What if there is more than one eligible?” [1]

This is really quite silly, as the same problem happens with the known evil, goto:

10 PRINT "Joe is great"
10 PRINT "Joe is dumb"
20 GOTO 10

Different languages handle this in different ways, but most languages with first-class comefrom support call it an error. [2]

A runtime error is cowardly evasion!

With a few seconds of thought, it becomes obvious that the modern fascination with “pub-sub” frameworks is merely an attempt to shoehorn comefrom into languages without it. Such attempts are clearly inferior to the first-class support in Cf0x10, but they do illustrate that people have no fundamental problem with multiple comefrom dispatch; it should, therefore, not be an error.

The problem such frameworks all encounter is that programs written with them turn out to be very hard to understand. They’ve figured out an ordering when multiple handlers react to the same event, but, because they are tacked on after a language is designed, they must determine the order dynamically. In other words, which part responds to what event becomes undecidable.

Cf0x10, however, embeds publish-subscribe right in the core of its design, enabling you to determine in lexical scope what parts of the program may respond to an event. It follows a few simple rules:

  1. Blank lines yield to any comefrom statement in inverted lexical scope
  2. When more than one comefrom is an eligible jump target in a single scope, the last wins, in source-code order
  3. Execution jumps to the current scope after jumping to eligible comefrom statements in nested scopes
  4. Nested-scope comefrom statements execute depth-first, as seen in source code indentation, where blocks that are first in the source are executed first

That’s it! With four simple rules, you can see at a glance which code will run upon what condition.

See also


[1]According a scientific poll of one, yours truly
[2]What I think it would do in Intercal, if I were actually smart enough to write an Intercal program.