[HELP] : how can I write a goto in ruby

Hi all,

i am writing an embedded lisp interpretor in ruby, and i noticed that
i ABSOLUTELY need to use a goto or another thing that reacts
like the goto. I found a link :

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

but i can’t get the file because the download link is died.

Thanks for all

Sébastien
Université Paris 8, France
DESS Informatique des Systèmes Autonomes

“smayemba” aidez.moi@free.fr schrieb im Newsbeitrag
news:4003bb39$0$17144$626a54ce@news.free.fr

Hi all,

i am writing an embedded lisp interpretor in ruby, and i noticed that
i ABSOLUTELY need to use a goto or another thing that reacts
like the goto. I found a link :

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

but i can’t get the file because the download link is died.

I’m curious why you need “goto” so desperately. Can you explain that? I
bet there is a better way.

Regards

robert

Are you familiar with the “catch” method? It implements a common use
for goto (escaping several loops at once - catch even works through
method boundaries).

If you want longjmp-like behavious, try continuations. The Pickaxe is
the place to go for both of these topics.

Cheers,
Gavin

···

On Tuesday, January 13, 2004, 8:36:37 PM, smayemba wrote:

Hi all,

i am writing an embedded lisp interpretor in ruby, and i noticed that
i ABSOLUTELY need to use a goto or another thing that reacts
like the goto. I found a link :

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

but i can’t get the file because the download link is died.

I am working in an university project. I have to translate an embedded lisp
interpretor wrote in Java in another language. I chose Ruby. In the java
code,
i don’t success to translate that kind of code in Ruby :

public static void eval()
{
begin_eval: //label (1)
while( 1 )
{
//some code come here

        evalcar:    //label (2)
            while( 1 )
            {
                switch( x )
                {
                    case
                        ...
                    default :
                        if foo
                            break begin_eval //goto (1)
                        continue evalcar //goto (2)
                }
            }
    }

}

In ruby i don’t know how to translate a <> and <<continue

. It’s like some goto ??

Thanks

Sébastien
Université Paris 8, France
DESS Informatique des Systèmes Autonomes

“smayemba” aidez.moi@free.fr a écrit dans le message de
news:4003bb39$0$17144$626a54ce@news.free.fr

···

Hi all,

i am writing an embedded lisp interpretor in ruby, and i noticed that
i ABSOLUTELY need to use a goto or another thing that reacts
like the goto. I found a link :

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

but i can’t get the file because the download link is died.

Thanks for all

Sébastien
Université Paris 8, France
DESS Informatique des Systèmes Autonomes

//////////////// Thanks for all guys. It works fine. ////////////////

Sébastien

“smayemba” aidez.moi@free.fr schrieb im Newsbeitrag
news:4003e1cb$0$17143$626a54ce@news.free.fr

I am working in an university project. I have to translate an embedded
lisp
interpretor wrote in Java in another language. I chose Ruby. In the java
code,
i don’t success to translate that kind of code in Ruby :

public static void eval()
{
begin_eval: //label (1)
while( 1 )
{
//some code come here

        evalcar:    //label (2)
            while( 1 )
            {
                switch( x )
                {
                    case
                        ...
                    default :
                        if foo
                            break begin_eval //goto (1)
                        continue evalcar //goto (2)
                }
            }
    }

}

In ruby i don’t know how to translate a <> and <<continue

. It’s like some goto ??

You can use “next” and “break”:

def eval_lisp
loop do

# some code come here

loop do
  case
  # ...
  else
    break if foo
    next
  end
end

end
end

Regards

robert

Try:

class Lisper
def eval
loop do
catch :begin_eval do
# some code here
loop do
# you may not need this one unless there’s other inner
# loops
catch :eval_car do
case x
when …
else
# continues looping from :begin_eval
throw :begin_eval if foo
throw :eval_car # could just be done with next
end
end
end
end
end
end
end

Breaking to a labelled loop isn’t directly possible in Ruby, but you
can wrap the body of a loop in a catch block, and then throw the
expected symbol to simulate it.

You can simplify the above code by doing:

def Kernel
alias_method :old_loop, :loop
def loop(label = nil, &block)
if label.nil?
old_loop &block
else
old_loop { catch label &block }
end
end
end

Your resulting code would then be:

class Lisper
def eval
loop (:begin_eval) do
# some code here
loop (:eval_car) do
# you may not need this one unless there’s other inner
# loops
case x
when …
else
# continues looping from :begin_eval
throw :begin_eval if foo
throw :eval_car # could just be done with next
end
end
end
end
end

-austin

···

On Tue, 13 Jan 2004 21:21:40 +0900, smayemba wrote:

I am working in an university project. I have to translate an
embedded lisp interpretor wrote in Java in another language. I
chose Ruby. In the java code, i don’t success to translate that
kind of code in Ruby :
public static void eval()
{
begin_eval: //label (1)
while( 1 )
{
//some code come here
evalcar: //label (2)
while( 1 )
{
switch( x )
{
case

default :
if foo
break begin_eval //goto (1)
continue evalcar //goto (2)
}
}
}
}

In ruby i don’t know how to translate a <> and
<> . It’s like some goto ??


austin ziegler * austin@halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2004.01.13
* 09.00.32

“Robert Klemme” bob.news@gmx.net a écrit dans le message de
news:bu0on3$c9h3l$1@ID-52924.news.uni-berlin.de

You can use “next” and “break”:

def eval_lisp
loop do

# some code come here

loop do
  case
  # ...
  else
    break if foo
    next
  end
end

end
end

Regards

robert

i am going to try it later. Hope u right. Thanks a lot

Sébastien

“Robert Klemme” bob.news@gmx.net a écrit dans le message de
news:bu0on3$c9h3l$1@ID-52924.news.uni-berlin.de

You can use “next” and “break”:

def eval_lisp
loop do

# some code come here

loop do
  case
  # ...
  else
    break if foo
    next
  end
end

end
end

Regards

robert

i am going to try it later. Hope u right. Thanks a lot

Sébastien

Hi,

                        if foo
                            break begin_eval //goto (1)

This should exit outer loop.

You can use “next” and “break”:

def eval_lisp
loop do

# some code come here

loop do
  case
  # ...
  else
    break if foo

So “return” instead of “break” should be here.

···

At Tue, 13 Jan 2004 21:36:37 +0900, Robert Klemme wrote:


Nobu Nakada

nobu.nokada@softhome.net schrieb im Newsbeitrag
news:200401131327.i0DDRLnu007049@sharui.nakada.kanuma.tochigi.jp…

Hi,

                        if foo
                            break begin_eval //goto (1)

This should exit outer loop.

You can use “next” and “break”:

def eval_lisp
loop do

# some code come here

loop do
  case
  # ...
  else
    break if foo

So “return” instead of “break” should be here.

Oh, yes of course. Thanks! Alternatively one could use throw catch if
some work has to be done after the outer loop. That would then result in
this version:

def eval_lisp
catch :begin_eval do
loop do

  # some code come here

  loop do
    case
    # ...
    else
      throw :begin_eval if foo
      next
    end
  end
end

end

work after loop

end

Regards

robert
···

At Tue, 13 Jan 2004 21:36:37 +0900, > Robert Klemme wrote: