[linux-elitists] Goto vs. named scopes

Jay Sulzberger jays@panix.com
Sat Jan 11 12:39:59 PST 2003

On Sat, 11 Jan 2003, Jim Bray wrote:

> >
> > What I find over the years is that like most everything else, goto is abused.
> > There are certain cases where a goto works best, and it's hard to dispute
> > that. As an example, (W.) Richard Stevens used goto statements in some of his
> > socket routines, and I would challenge someone to come up with a better
> > solution to the problem at hand in less machine cycles. It just can't be done.
>   Back in the early 1980s I came up with ideas for dealing with this.
> Allow all scopes to be named, and allow break and continue to operate
> with those names. Add to those a 'restart' operation and you're pretty
> much all set.
> outer: {
> 	get_lock: for (...) {
> 		sleep();
> 		if (interrupted)
> 			restart get_lock;
> 		if (error)
> 			break outer;
> 	}
> 	more code;
> }

There was much discussion of such devices throughout the Sixties of the
last century.  One popular standard come-from:go-to faculty is Scheme's
call-with-current-continuation, often called "call/cc".  The Scheme
standard's explanation of call/cc is not easy to understand, but the
difficulty lies in the explanation, not in the general idea of call/cc.
The syntax might be slightly different from most come-from:go-to
constructs, but, as usual, Scheme has the advantage here.


What do you want of a come-from:go-to pair?  You want

1. a handle on the place to be jumped to

2. a way to send stuff along with the racing blue dot of execution at jump

call/cc gives you both.  The jump command is given a name and you may pass
the jump command around as you may pass any procedure in (any) Lisp.  The
place that is jumped to is just before/above the place call/cc is
invoked/written, but the blue dot turns around and faces back/above before
it lands.  "facing the other way" is most of the meaning of the mysterious
"continuation".  The jump command takes one, or possibly more, inputs, and,
when executed, jumps the blue dot to the place before/above the call/cc,
and passes its input to whatever is waiting for the return value of the
call to call/cc.

Oi!  This is as bad and worse than the standard's words.  But naturally,
there are some Schemers on this list, and perhaps they will explain call/cc
right.  It is not difficult, and though there be obscurities near by, they
are not what puzzle the debutante here.


>  The original posting:
> http://groups.google.com/groups?q=jbray%40bbncca&start=10&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=177%40bbncca.ARPA&rnum=15

More information about the linux-elitists mailing list