ANN: ruby-goto, your evil for the evening

OK, so I was feeling evil last week sometime. Some people were claiming
that ruby did not, in fact, support goto, and that certain constructs
(like exceptions or catch/throw) were not equivalent, and that any
language with goto is pure evil.

If the latter is true, I am here to annouce that ruby is, in fact, pure
evil:

require 'goto'


def test
  frame_start

  label(:start) { goto :b }
  label(:a) { print "world!\n"; goto :c }
  label(:b) { print "hello "; goto :a }

  label(:c)

  frame_end
end


frame_start

label(:a) { test }
label(:b) { goto :a }

frame_end

This does exactly what it appears to do. The RAA entry, which points to
a copy of the module (which is written in pure Ruby), is here:

http://raa.ruby-lang.org/list.rhtml?name=ruby-goto

Stay tuned for the next evil module… ruby-malloc! Have a nice day.

:wink:

···


Ryan Pavlik rpav@users.sf.net

“It’s like I’m at least twice as evil as I used to be!” - 8BT

Now for your next trick… A “come from”.

No, wait, we’ve got that already.

It’s called the Observer pattern.

···

On Fri, 2003-06-06 at 17:13, Ryan Pavlik wrote:

and that any
language with goto is pure evil.


John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : john.carter@tait.co.nz
New Zealand

Carter’s Fundamental…

The universe is driven entirely by this single rule, and everything at
all scales may be understood by it…

“Things only ever go right, so that they may go more spectacularly wrong
later.”

This is great! But the really scary thing is that I was thinking about
doing something similar, but using continuations. The exception
implementation is much more straight forward (and much more evil …
people expect weird things from continuations).

The only changes I would suggested is using …

frame {
  label(:lab) { ... }
  ...
}

instead of frame_start/frame_end (now you have your first evil change
request).

···

On Fri, 2003-06-06 at 01:13, Ryan Pavlik wrote:

OK, so I was feeling evil last week sometime. Some people were claiming
that ruby did not, in fact, support goto, and that certain constructs
(like exceptions or catch/throw) were not equivalent, and that any
language with goto is pure evil.

If the latter is true, I am here to annouce that ruby is, in fact, pure
evil:


– Jim Weirich jweirich@one.net http://onestepback.org

“Beware of bugs in the above code; I have only proved it correct,
not tried it.” – Donald Knuth (in a memo to Peter van Emde Boas)

Actually, COME FROM isn’t equivalent to Observer, as the former is an
assertion as to flow control, requiring the current statement to have
been reached from the specified line or label. It acts as a “trapdoor”,
causing code to be reached from the given line or label with no
visible interaction at the specified origin.

An Observer, on the other hand (and especially in a hand which happens
to be writing Ruby), does not require a particular unique origin (an
observer may observe multiple things) or provide an invisible trapdoor.

Unfortunately, Ruby seems to lack important features that could be used
to implement COME FROM, at least without heavy use of eval(). These
features include (but are not limited to) the following:

*  Code preevaluation.  If ruby code was evaluated, and the result
   of this evaluation able to in turn be evaluated before execution,
   one could search for COME FROM statements and set up the proper
   execution path.

*  Dry run.  If ruby code could first be run without effect, thus
   triggering COME FROM statements, allowing them to be recorded,
   they could be implemented without much trouble.

*  Reverse execution.  If ruby code could be evaluated, and then run
   backwards from finish to start, the given "goto" package would,
   effectively, be COME FROM, as the last code would be executed
   first, followed by the call to the actual GOTO.  Proper aliasing
   of "goto" to "come_from", a feature already supported by ruby,
   would ensure proper semantic aesthetics.  With this feature, one
   could simply write his or her ruby code backwards, except for
   aliased gotos.

As you can see, this analysis of COME FROM vs Observer, and the features
required to implement it, show that I have far too much free time.
This should be remedied by an upcoming “time” module, which will allow
ruby threads to have been executed at a given time. I just need a few
things added to Ruby first…

···

On Fri, 6 Jun 2003 15:25:04 +0900 John Carter john.carter@tait.co.nz wrote:

On Fri, 2003-06-06 at 17:13, Ryan Pavlik wrote:

and that any
language with goto is pure evil.

Now for your next trick… A “come from”.

No, wait, we’ve got that already.

It’s called the Observer pattern.

Ryan Pavlik rpav@users.sf.net

“It’s like I’m at least twice as evil as I used to be!” - 8BT

Already been done. Intercal has a “come from” statement. :slight_smile:

Joey

···

On Fri, 6 Jun 2003 15:25:04 +0900, John Carter john.carter@tait.co.nz wrote:

On Fri, 2003-06-06 at 17:13, Ryan Pavlik wrote:

and that any
language with goto is pure evil.

Now for your next trick… A “come from”.


Dean saor, dean saor an spiorad. Is seinn d’orain beo.

> This is great! But the really scary thing is that I was thinking about > doing something similar, but using continuations. The exception > implementation is much more straight forward (and much more evil ... > people expect weird things from continuations).

Yeah… one thing I was trying to show at the time was the fact that
goto was useful (in C) for things like exceptions and similar error
handling (like unwind-protect) since the language sadly lacks both.
This was just showing equivalence by going in the opposite direction,
or something. :wink:

The only changes I would suggested is using …

frame {
  label(:lab) { ... }
  ...
}

instead of frame_start/frame_end (now you have your first evil change
request).

I considered this, among other things (making it threadsafe for one).
The frame{} way would probably be the best and take care of both
problems, since it would eliminate the need for a global “frame
stack”. Although without that, I couldn’t add support for long
jumps… >;) There are other possibilities, like implicit
frame_starts, but since I don’t think this is likely to be used much,
I didn’t go to a whole lot of trouble. Maybe this weekend I’ll
release version negative two if I get a chance. :wink:

···

On Fri, 6 Jun 2003 20:56:57 +0900 Jim Weirich jweirich@one.net wrote:


Ryan Pavlik rpav@users.sf.net

“They be like a thorny thorn in ye sidey side.” - 8BT

I think somebody should tell Ryan that something useful cannot be
done in Ruby. :wink:

···

On Friday, June 6, 2003, at 03:14 AM, Ryan Pavlik wrote:

[snip]

As you can see, this analysis of COME FROM vs Observer, and the
features
required to implement it, show that I have far too much free time.
[snip]

I think he is riped enough to takle the great task of implementing
esoteric languages in ruby (ook, available in RAA is an example). See
DM's Esoteric Programming Languages.

The language Whenever for example execute a statement when it feels like
it and the statements in a program are not executed in order. Wouldn’t
that be a great addition to ruby?

Go for it, I sign up as a beta tester…

Guillaume.

···

On Fri, 2003-06-06 at 04:47, Mark Wilson wrote:

On Friday, June 6, 2003, at 03:14 AM, Ryan Pavlik wrote:

[snip]

As you can see, this analysis of COME FROM vs Observer, and the
features
required to implement it, show that I have far too much free time.
[snip]

I think somebody should tell Ryan that something useful cannot be
done in Ruby. :wink:

Guillaume Marcais guslist@free.fr writes:

···

On Fri, 2003-06-06 at 04:47, Mark Wilson wrote:

On Friday, June 6, 2003, at 03:14 AM, Ryan Pavlik wrote:

[snip]

As you can see, this analysis of COME FROM vs Observer, and the
features
required to implement it, show that I have far too much free time.
[snip]

I think somebody should tell Ryan that something useful cannot be
done in Ruby. :wink:

I think he is riped enough to takle the great task of implementing
esoteric languages in ruby (ook, available in RAA is an example). See
DM's Esoteric Programming Languages.

The language Whenever for example execute a statement when it feels like
it and the statements in a program are not executed in order. Wouldn’t
that be a great addition to ruby?

Go for it, I sign up as a beta tester…

Guillaume.

In addition, now that there’s a GOTO statement, for symmetry, we need
the COMEFROM statement that was first implemented in the INTERCAL
language. See here for details about this hallowed tradition:

The INTERCAL Programming Language Revised Reference Manual


Lloyd Zusman
ljz@asfast.com