[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: continuation

Carlos

2/5/2006 1:35:00 AM

[Schüle Daniel <uval@rz.uni-karlsruhe.de>, 2006-02-05 01.58 CET]
> 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?Con...
> 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.

--