Yes, I fixed the file.close thing.
It was something I missed, the main problem I had was to get the script
to "start over".
Thanks everybody..
"David Vallner" <david@vallner.net> writes:
The BASIC construct of "goto" is rightfully considered harmful for
programs above a certain complexity. It's not present in Ruby in any
direct way that would let you jump around a program's structure
arbitrarily. (Actually, that's a lie, but I'll hold the continuations
for the sake of simplicity.)
It is often said that continuations are as powerful as goto.
But is there a way to jump *forward* with continuations, without
rewriting the code to use additional methods?
Oh, interesting.
To the OP: It's usually advised to break a method into several, if you
find that it gets too long or has too many levels of indentation.
···
On Wed, Oct 10, 2012 at 5:05 AM, Peter Zotov <whitequark@whitequark.org> wrote:
Eric Christopherson писал 10.10.2012 02:12:
On Tue, Oct 9, 2012 at 4:45 PM, Frédéric Lemire <lists@ruby-forum.com> >> wrote:
...I like cleanliness and modularization, but I also like to have the eval
command, and metaprogramming stuff to explore sometimes unexpected ways.
So, why not a goto command ?It's neat to be able to get dirty when one needs it and feels confident
about it !Anyway… for now, I'll just make exceptions to my indentation fixation,
waiting for a freer future.You can use continuations (although I think I recall hearing that they
were either removed or dumbed down in 1.9).They were, in fact, added in 1.9.
Neither, actually -- callcc is present in both 1.8.7 and 1.9, but was moved from the core to a stdlib in 1.9 (the 'continuation' module).
However, callcc is not guaranteed to be present in all implementations (and is in fact not present in JRuby and MacRuby).
I use callcc as the basis for the (mostly humorous/proof-of-concept) "reconsidered" gem, which -- to the original poster's question -- adds a limited form of goto to ruby, and for the more serious ambit gem, which provides nondeterministic programming for Ruby, and is the basis for the in-progress rulog logic programming system for Ruby.
See:
for more on reconsidered, ambit, and rulog.
···
On Oct 10, 2012, at 06:05 , Peter Zotov <whitequark@whitequark.org> wrote:
Eric Christopherson писал 10.10.2012 02:12:
On Tue, Oct 9, 2012 at 4:45 PM, Frédéric Lemire <lists@ruby-forum.com> wrote:
...I like cleanliness and modularization, but I also like to have the eval
command, and metaprogramming stuff to explore sometimes unexpected ways.
So, why not a goto command ?It's neat to be able to get dirty when one needs it and feels confident
about it !Anyway… for now, I'll just make exceptions to my indentation fixation,
waiting for a freer future.You can use continuations (although I think I recall hearing that they
were either removed or dumbed down in 1.9).They were, in fact, added in 1.9.
--
Jim Wise
jwise@draga.com
Eric Christopherson писал 10.10.2012 02:12:
...
I like cleanliness and modularization, but I also like to have the eval
command, and metaprogramming stuff to explore sometimes unexpected ways.
So, why not a goto command ?It's neat to be able to get dirty when one needs it and feels confident
about it !Anyway… for now, I'll just make exceptions to my indentation fixation,
waiting for a freer future.You can use continuations (although I think I recall hearing that they
were either removed or dumbed down in 1.9).They were, in fact, added in 1.9.
No, they were added MUCH earlier than 1.9.
RUBY_VERSION
=> "1.8.7"
callcc {}
=> nil
In fact, way way earlier than that:
10024 % cd ruby_1_4
10025 % ag callcc
./ChangeLog
2301: * eval.c (rb_callcc): call scope_dup() for all scopes in
3127: * eval.c (rb_callcc): experimental continuation support.
./eval.c
7518:rb_callcc(self)
7616: rb_define_global_function("callcc", rb_callcc, 0);
···
On Oct 10, 2012, at 03:05 , Peter Zotov <whitequark@whitequark.org> wrote:
On Tue, Oct 9, 2012 at 4:45 PM, Frédéric Lemire <lists@ruby-forum.com> wrote:
From: Nathan Smith [mailto:nsmith5@umbc.edu]
Sent: Tuesday, August 15, 2006 3:09 PM
To: ruby-talk ML
Subject: Re: goto function?> > I want the script to start over again.. for example..
> > When the user made an input and pressed return I want the
script to
> > "restart" or jump to the beginning..
> >
>
> Let me introduce you to my good friend: structured
programming. I'm sure
> you'll get along marvelous once you get to know each other.
>
> The BASIC construct of "goto" is rightfully considered harmful for
> programs above a certain complexity. It's not present in Ruby in any
> direct way that would let you jump around a program's structure
> arbitrarily. (Actually, that's a lie, but I'll hold the
continuations for
> the sake of simplicity.)<snip>
Obligatory response:
In some very rare circumstances, using gotos does in fact
have a rightful
place in code. In very long switch/case statements in C code, a _very_
well structured (and properly named) set of labels/gotos can make code
much cleaner, and easier to understand, than if they were not
used. But
I'll say again, this is very rare.
I have to respectfully disagree. Having actively used C (among many
others) since 1986 up until now for professional development, I NEVER
found a good use for it, even in my early days. Especially in
switch/case statements ;-). It may be _very_ well structured in the
beginning, becoming a total mess with time. Never had very long
switch/case statements even on very big projects either. This is where
lookup tables with function pointers come in handy, for one.
Gennady.
···
-----Original Message-----
On Wed, 16 Aug 2006, David Vallner wrote:
> On Tue, 15 Aug 2006 23:05:10 +0200, fabsy > <fabbyfabs@gmail.com> wrote:
Nate
A continuation is, by definition, the *continuation* of the
computation. But that probably wasn't the answer you wanted. There's
no way to do:
goto :a
label :a
Even though it's easy to create label and goto methods that work like this:
label :a
puts "after a"
goto :a if rand(2) % 2 == 0
···
On 8/16/06, Christian Neukirchen <chneukirchen@gmail.com> wrote:
"David Vallner" <david@vallner.net> writes:
> The BASIC construct of "goto" is rightfully considered harmful for
> programs above a certain complexity. It's not present in Ruby in any
> direct way that would let you jump around a program's structure
> arbitrarily. (Actually, that's a lie, but I'll hold the continuations
> for the sake of simplicity.)It is often said that continuations are as powerful as goto.
But is there a way to jump *forward* with continuations, without
rewriting the code to use additional methods?> David Vallner
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org
--
- Simen
"David Vallner" <david@vallner.net> writes:
The BASIC construct of "goto" is rightfully considered harmful for
programs above a certain complexity. It's not present in Ruby in any
direct way that would let you jump around a program's structure
arbitrarily. (Actually, that's a lie, but I'll hold the continuations
for the sake of simplicity.)It is often said that continuations are as powerful as goto.
But is there a way to jump *forward* with continuations, without
rewriting the code to use additional methods?
Jumping forward:
callcc do |cc|
puts "Some code"
puts "Some more code"
cc.call # jump forward
puts "I'm never executed"
end
puts "Whee!"
···
On Aug 16, 2006, at 7:55 AM, Christian Neukirchen wrote:
David Vallner
-- Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org
As others said, continuations continue. You can jump backwards, because you know the whole context to jump into - it already existed.
To jump forward in code without explicitly setting up a context in which to run would either result in undefined behaviour, accepting some defaults for the context (all local / instance / other nonglobal variables are nil, for example), or the timespace continuum breaking. That might not apply if you were scripting a time machine, of course.
This is precisely why goto is considered harmful in the first place - to jump forward, you have to use only global context, or some other context that is defined to be shared when using such a construct. It would be interesting however if there was a concept of capture a (possible) future point of code execution without having to do explicit setup via a command object or something similar. I'll admit at this point that my savvy gets a little fuzzy around very high level programming theory - so I might actually be honking wrong in which case I'm all ears intrigued as to the workings of that construct.
David Vallner
···
On Wed, 16 Aug 2006 13:55:01 +0200, Christian Neukirchen <chneukirchen@gmail.com> wrote:
It is often said that continuations are as powerful as goto.
But is there a way to jump *forward* with continuations, without
rewriting the code to use additional methods?
I'm guessing he was probably thinking of Fibers
···
On Wed, Oct 10, 2012 at 2:01 PM, Ryan Davis <ryand-ruby@zenspider.com>wrote:
> Eric Christopherson писал 10.10.2012 02:12:
> They were, in fact, added in 1.9.No, they were added MUCH earlier than 1.9.
--
Tony Arcieri
Simen Edvardsen schrieb:
There's no way to do:
goto :a
label :a
Right, but with some evil Ruby code, this is possible:
irb(main):001:0> require "goto"
=> true
irb(main):002:0> with_goto do
irb(main):003:1*
irb(main):004:1* puts 1
irb(main):005:1> goto :b
irb(main):006:1>
irb(main):007:1* label :a
irb(main):008:1> puts 3
irb(main):009:1> goto :c
irb(main):010:1>
irb(main):011:1* label :b
irb(main):012:1> puts 2
irb(main):013:1> goto :a
irb(main):014:1>
irb(main):015:1* label :c
irb(main):016:1> puts 4
irb(main):017:1>
irb(main):018:1* end
1
2
3
4
=> nil
irb(main):019:0>
No, I won't show the implementation yet. See http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/202387
Regards,
Pit
Ah very clever. Corrupting the minds of the innocent by introducing
bad programming practices to the language.
This reminds me of a conversation I had with one of my junior
programmers on a project back in the 80's. He argued that since the C
language specification included the GOTO statement it was perfectly
fine to use it. I pointed out that my Jeep had a roll bar, but that
didn't mean I should use it!