From: Sam Kong Date: 2006-10-12T09:07:30+09:00 Subject: Re: Question about callcc Hi Ken, Ken Bloom wrote: > On Thu, 12 Oct 2006 01:59:26 +0900, Carlos wrote: > >>> callcc { |c| $label = c } >>> As I understand it, callcc returns the last expression or return value >> Try >> $label = callcc {|c| c} >> $label.call(3) >> >> and >> $label = callcc {|c| puts "first call"; c} >> $label.call(lambda{puts "second call"}) >> >> to understand what's going on. > > This example (run in straight ruby, not irb) should clarify what's going > on. > > begin > $label=nil > $label=callcc{|c| c} > puts "After the first callcc" > $label.call > rescue StandardError=>e > puts e > end > > begin > $label=nil > callcc{|c| $label=c} > puts "After the second callcc" > $label.call > rescue StandardError=>e > puts e > end > > [bloom@cat-in-the-hat ~]$ ruby callcc.rb | head > After the first callcc > After the first callcc > undefined method `call' for nil:NilClass > After the second callcc > After the second callcc > After the second callcc > After the second callcc > After the second callcc > After the second callcc > After the second callcc > (infintie loop) Although I still don't understand what's going on in the back, I see the difference. Thank you very much. Sam -- Posted via http://www.ruby-forum.com/.