| ▲ | taeric 7 hours ago | |||||||||||||||||||||||||||||||
I confess I like Common Lisp's TAGBODY far more than I feel like I should. Having constrained GOTO semantics to a short section of the codebase is surprisingly useful. | ||||||||||||||||||||||||||||||||
| ▲ | adrian_b 4 hours ago | parent | next [-] | |||||||||||||||||||||||||||||||
Following the recommendations of Knuth, the language Mesa, which was implemented at Xerox during the seventies, and which was a source of inspiration for various later languages, including Modula, Ada and Python, included a form of "restricted GOTO" which is the most useful kind of GOTO in my opinion. The Mesa restricted GOTO allowed jumping forwards, but not backwards, and it allowed jumping towards an outer block, but not towards an inner block. These 2 restrictions eliminate all the "harmful" features of the traditional GOTO, while retaining its advantages for handling exceptional conditions or for terminating multiple levels of nested program structures. The Common Lisp TAGBODY appears to be only partially restricted, by allowing backward jumps, so it does not prevent the kind of hard-to-understand program structures for which GOTO was criticized. GOTOs in random directions may be used to implement state machines, but such state machines can still be implemented in a language with restricted GOTO by not using GOTO, but by using mutually recursive procedures, if tail-call optimization is guaranteed. | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
| ▲ | pmcgoron 5 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
From John Cowan: TAGBODY doesn't actually require continuations, delimited or undelimited, just proper tail calling. A macro can rewrite each section of the TAGBODY into a procedure nested within a `let` that tail-calls its successor, and the body of the `let` tail-calls the first procedure. (GO tag) is then equivalent to just (tag). This is a great way of doing state machines. Chicken has a tagbody egg, I think. | ||||||||||||||||||||||||||||||||
| ▲ | kccqzy 7 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
Constrained GOTO semantics sounds a lot like delimited continuations. Indeed I think Scheme continuations are a little too powerful for regular use by having the possibility of global effect (like longjmp). Delimited continuations make the effect more local. | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
| ▲ | Joker_vD 5 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
Do you use it mostly as "labeled breaks" or to throw the values out of closures? | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
| ▲ | 4 hours ago | parent | prev [-] | |||||||||||||||||||||||||||||||
| [deleted] | ||||||||||||||||||||||||||||||||