Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > continuation

Reply
Thread Tools

continuation

 
 
Ross Bamford
Guest
Posts: n/a
 
      02-05-2006
On Sun, 05 Feb 2006 02:49:58 -0000, Schüle Daniel
<> wrote:

> irb(main):005:0* cnt=0
> => 0
> irb(main):006:0> cc=nil
> => nil
> irb(main):007:0> callcc {|cc|}
> => nil
> irb(main):008:0> cnt+=1
> => 1
> irb(main):009:0> cc.call if cnt < 10
> => nil
> irb(main):010:0> cnt
> => 1
> irb(main):011:0>
> irb(main):012:0* RUBY_VERSION
> => "1.8.4"
> irb(main):013:0>
>
> this example is from
> http://www.rubygarden.org/ruby?Continuations
> and cnt should become 10
>


I've found that certain things like continuations don't work well under
IRB. I think it's because of the way it's workspaces work.

That code works fine as a script.

--
Ross Bamford -
 
Reply With Quote
 
 
 
 
angus
Guest
Posts: n/a
 
      02-05-2006
[Sch=FCle Daniel <>, 2006-02-05 01.58 CET]
> Hello,
>=20
> irb(main):005:0* cnt=3D0
> =3D> 0
> irb(main):006:0> cc=3Dnil
> =3D> nil
> irb(main):007:0> callcc {|cc|}
> =3D> nil
> irb(main):008:0> cnt+=3D1
> =3D> 1
> irb(main):009:0> cc.call if cnt < 10
> =3D> nil
> irb(main):010:0> cnt
> =3D> 1
> irb(main):011:0>
> irb(main):012:0* RUBY_VERSION
> =3D> "1.8.4"
> irb(main):013:0>
>=20
> this example is from
> http://www.rubygarden.org/ruby?Continuations
> and cnt should become 10


The problem is IRB. It is a ruby program whose main loop reads your input=
,
evaluates it, and shows you the result, so when you call the continuation=
,
it only returns to the point where it shows you the result of your input;
it doesn't evaluate the statementes you entered later.

Try the example outside IRB.

--=20


 
Reply With Quote
 
 
 
 
Schüle Daniel
Guest
Posts: n/a
 
      02-05-2006
Hello,

irb(main):005:0* cnt=0
=> 0
irb(main):006:0> cc=nil
=> nil
irb(main):007:0> callcc {|cc|}
=> nil
irb(main):008:0> cnt+=1
=> 1
irb(main):009:0> cc.call if cnt < 10
=> nil
irb(main):010:0> cnt
=> 1
irb(main):011:0>
irb(main):012:0* RUBY_VERSION
=> "1.8.4"
irb(main):013:0>

this example is from
http://www.rubygarden.org/ruby?Continuations
and cnt should become 10

I also tried some other examples from the net
and it worked only in this case

irb(main):014:0* callcc do |cc|
irb(main):015:1* for i in 0..10
irb(main):016:2> print "\n#{i}: "
irb(main):017:2> for j in 0..10
irb(main):018:3> cc.call if j == 5 and i == 5
irb(main):019:3> printf "%3i", j
irb(main):020:3> end
irb(main):021:2> end
irb(main):022:1> end

0: 0 1 2 3 4 5 6 7 8 9 10
1: 0 1 2 3 4 5 6 7 8 9 10
2: 0 1 2 3 4 5 6 7 8 9 10
3: 0 1 2 3 4 5 6 7 8 9 10
4: 0 1 2 3 4 5 6 7 8 9 10
5: 0 1 2 3 4=> nil
irb(main):023:0>

Maybe someone can help

Regards, Daniel

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
help me to split the display of the contents of an ASP page into 2 pages by having the continuation aarthy kumar ASP .Net 3 10-12-2005 12:30 PM
Continuation question.... DC ASP .Net 2 05-24-2005 03:59 PM
Parameter continuation algorithms in Python? bgoli Python 0 10-24-2003 02:30 PM
stackless python: continuation module? TheDustbustr Python 2 08-06-2003 05:55 PM
why window.open script not firing? just postback...continuation of previous post KathyB ASP .Net 2 07-17-2003 02:21 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57