Go LABEL

Can we do a " go label " in ruby just like in asm? i cant find any
example or documentation about this...

for example...
if()
some codes
go LabelA

else
some other codes
go LabelB

end

LabelA:

codes

LabelB:

codes

···

--
Posted via http://www.ruby-forum.com/.

goto

http://raa.ruby-lang.org/project/ruby-goto/

···

On Tue, Dec 23, 2008 at 9:48 PM, Xx Xx <limhuisian@hotmail.com> wrote:

Can we do a " go label " in ruby just like in asm? i cant find any
example or documentation about this...

for example...
if()
some codes
go LabelA

else
some other codes
go LabelB

end

LabelA:

codes

LabelB:

codes
--
Posted via http://www.ruby-forum.com/\.

How surreal... someone named RubyTalk is posting to ruby-talk and instructing us to goto a project called ruby-goto. :stuck_out_tongue:

RubyTalk@gmail.com wrote:

···

goto

http://raa.ruby-lang.org/project/ruby-goto/

On Tue, Dec 23, 2008 at 9:48 PM, Xx Xx <limhuisian@hotmail.com> wrote:

Can we do a " go label " in ruby just like in asm? i cant find any
example or documentation about this...

for example...
if()
some codes
go LabelA

else
some other codes
go LabelB

end

LabelA:

codes

LabelB:

codes
--
Posted via http://www.ruby-forum.com/\.

--
       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

Cant download from the link http://raa.ruby-lang.org/project/ruby-goto/

Link broken?

···

--
Posted via http://www.ruby-forum.com/.

IMHO "goto" is the worst tool you can use. One of the alternatives is catch and throw

catch :foo do
...
throw :foo
...
throw :foo, any_value_you_like
...
end

Another helpful construct is "case" which can be used in two forms

case value
when condition
...
else
end

case
when expression
...
else
end

If you give us more information about the problem you are trying to solve we might be able to come up with better solutions.

Cheers

  robert

···

On 24.12.2008 07:36, Xx Xx wrote:

Cant download from the link http://raa.ruby-lang.org/project/ruby-goto/

Hi Xx,

Cant download from the link http://raa.ruby-lang.org/project/ruby-goto/

Link broken?

Just googling:
<http://raa.ruby-lang.org/cache/ruby-goto/ruby-goto.tar.gz&gt;\.

As the author himself admits
(<http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/72922&gt;\),
this is more a puzzle than of any functional avail.

You should be glad not to be tempted practising this dangerous
programming style. I did not miss the goto statement in any
language for about twenty-five years. Be confident.

Merry Christmas to all!

Bertram

···

Am Mittwoch, 24. Dez 2008, 15:36:27 +0900 schrieb Xx Xx:

--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de

Hi,

I agree on the case/when statement. But I don't think throw/catch is a true
alternative. It should be reserved for error handling only.

Regards,
Nicolai

Bertram Scharpf wrote:

Hi Xx,

You should be glad not to be tempted practising this dangerous
programming style. I did not miss the goto statement in any
language for about twenty-five years. Be confident.

Merry Christmas to all!

Bertram

I used goto to implement a parser for ISO 8601 (in C, generated by ruby)
and it is very handy for that. It's just too easy to implement a
statemachine with gotos. But besides generated code (which isn't
intended to be very readable) I do agree that goto is a bad choice.
I think it's just as bad to call a tool all-evil as to use a tool in the
wrong place.

Regards & merry christmas
Stefan

···

--
Posted via http://www.ruby-forum.com/\.

No, for error handling you use "raise" and "rescue". Please pay close attention to how "catch" and "throw" work, especially the fact that you can use a second argument to "throw" to pass an object (presumably the result of a calculation).

Cheers

  robert

···

On 24.12.2008 13:26, Codeblogger wrote:

I agree on the case/when statement. But I don't think throw/catch is a true
alternative. It should be reserved for error handling only.

As a matter of fact gotos can make your code clearer, but that has
been discovered a long time ago :wink: and those gotos have been disguised
into exit/break, continue, next, redo, case, throw-catch,
raise-rescue.
Modern languages like Ruby really have all the gotos you should wish for.
I however understand that you used gotos in your C state-machine.
But IIRC we were talking about Ruby-goto, right ;).

Cheers
Robert

···

On Thu, Dec 25, 2008 at 12:47 PM, Stefan Rusterholz <apeiros@gmx.net> wrote:

Bertram Scharpf wrote:

Hi Xx,

You should be glad not to be tempted practising this dangerous
programming style. I did not miss the goto statement in any
language for about twenty-five years. Be confident.

Merry Christmas to all!

Bertram

I used goto to implement a parser for ISO 8601 (in C, generated by ruby)
and it is very handy for that. It's just too easy to implement a
statemachine with gotos. But besides generated code (which isn't
intended to be very readable) I do agree that goto is a bad choice.
I think it's just as bad to call a tool all-evil as to use a tool in the
wrong place.

Robert Klemme wrote:

No, for error handling you use "raise" and "rescue". Please pay close attention to how "catch" and "throw" work, especially the fact that you can use a second argument to "throw" to pass an object (presumably the result of a calculation).

Then just use return.

(-:

···

--
   Phlip

If it can be used that would definitively my first choice. Sometimes it can't and in these - admittedly rather rare - circumstances you should rather use catch throw than goto IMHO.

Cheers

  robert

···

On 24.12.2008 16:21, Phlip wrote:

Robert Klemme wrote:

No, for error handling you use "raise" and "rescue". Please pay close attention to how "catch" and "throw" work, especially the fact that you can use a second argument to "throw" to pass an object (presumably the result of a calculation).

Then just use return.

--
remember.guy do |as, often| as.you_can - without end