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

S

smayemba

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
 
R

Robert Klemme

smayemba said:
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
 
G

Gavin Sinclair

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 :

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

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
 
S

smayemba

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 <<break label>> and <<continue
label>>. It's like some goto ??

Thanks

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

Robert Klemme

smayemba said:
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 <<break label>> and <<continue
label>>. 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
 
S

smayemba

Robert Klemme said:
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
 
S

smayemba

Robert Klemme said:
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
 
R

Robert Klemme

Hi,

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


This should exit outer loop.


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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,110
Latest member
OdetteGabb
Top