From: Robert Dober Date: 2007-06-07T06:03:07+09:00 Subject: Re: code problems On 6/6/07, Rick DeNatale wrote: > Robert, you are right, it loops in ruby, but not in irb. > > I was trying to cook up a simple example and got hoist by irb's petard. > > What happens in ruby is that calling the continuation goes back to the > method, which returns to the point before the cont.call and away we go > again. That confirms my limited understanding of it :) > > Continuations normally aren't reused in the way I did in the example. > I'm actually not sure why it works the way it does in irb. Hmm maybe I can give some hint in my zenwalk ruby 1.8.6 irb it loops as well as in my Windows (one click installer) irb, do you use a special irb setup? > > Here's a simpler example which shows the flow of control concept. > > rick@frodo:/public/rubyscripts$ cat testcontin.rb > def continuation > puts "Before callcc" > callcc {|cc| puts "In callcc";return cc} > puts "After callcc" > end > > puts "Begin" > cont = continuation > puts "Got cont #{cont.inspect}" > if cont > cont.call > puts "After call" > end > puts "All done" > rick@frodo:/public/rubyscripts$ ruby testcontin.rb > Begin > Before callcc > In callcc > Got cont # > After callcc > Got cont nil > All done That is a good example I really like to build on it. Thanks. Maybe I might add one thing which took me some minutes to work out ;) the nil value for the cont variable comes from : puts "After call". Cheers Robert -- You see things; and you say Why? But I dream things that never were; and I say Why not? -- George Bernard Shaw