Uestion about ruby continuations

Hi guys, I was playing with continuations in Scheme and decided to
port one puzzle from scheme to ruby. But it works in a different way.

Here is my code and explatations:
http://blog.gonzih.me/blog/2013/11/26/yin-yang-callcc-puzzle-in-ruby/

Can someone explain why is this happening?
Are there some limitations on how continuations can be used in ruby?
Thanks!

···

--
Regards,
Max

Hi Max Gonzih,

THANKS GOD IT'S FRIDAY !!!

lambda do |yin, yang|
  yin.call yang
end.call(lambda {|cc| print "@"; cc }.call(callcc { |c| c } ),
         lambda {|cc| print "*"; cc }.call(callcc { |c| c } ) )

The path was:
1) A good explanation of the algorithm over here:
    - call/cc yin-yang puzzle - Everything2.com
2) An explanation of Scheme "let" here:
    - Getting started

···

===
Let is only syntactic sugar for an underlying lambda application:

((lambda (var1 var2 ... varn)
   body)
exp1 exp2 ... expn)

And this made it easy for me to translate the algorithm into Ruby.

Best Regards,
Abinoam Jr.

PS: Run the "debug" version bellow and you will be able to see it "in action".

# "Debug" version
lambda do |yin, yang|
  yin.call yang
end.call(lambda {|cc| print "@ - #{cc}\n"; sleep 0.1; cc }.call(callcc
{ |c| c } ),
         lambda {|cc| print "* - #{cc}\n"; sleep 0.1; cc }.call(callcc
{ |c| c } ) )

Abinoam Jr.

On Tue, Nov 26, 2013 at 10:18 AM, Max Gonzih <gonzih@gmail.com> wrote:

Hi guys, I was playing with continuations in Scheme and decided to
port one puzzle from scheme to ruby. But it works in a different way.

Here is my code and explatations:
http://blog.gonzih.me/blog/2013/11/26/yin-yang-callcc-puzzle-in-ruby/

Can someone explain why is this happening?
Are there some limitations on how continuations can be used in ruby?
Thanks!

--
Regards,
Max

Now I get it. Great job, thank you!

···

On Fri, 2013-12-06 at 03:30 -0200, Abinoam Jr. wrote:

Hi Max Gonzih,

THANKS GOD IT'S FRIDAY !!!

lambda do |yin, yang|
  yin.call yang
end.call(lambda {|cc| print "@"; cc }.call(callcc { |c| c } ),
         lambda {|cc| print "*"; cc }.call(callcc { |c| c } ) )

The path was:
1) A good explanation of the algorithm over here:
    - call/cc yin-yang puzzle - Everything2.com
2) An explanation of Scheme "let" here:
    - Getting started

===
Let is only syntactic sugar for an underlying lambda application:

((lambda (var1 var2 ... varn)
   body)
exp1 exp2 ... expn)

And this made it easy for me to translate the algorithm into Ruby.

Best Regards,
Abinoam Jr.

PS: Run the "debug" version bellow and you will be able to see it "in action".

# "Debug" version
lambda do |yin, yang|
  yin.call yang
end.call(lambda {|cc| print "@ - #{cc}\n"; sleep 0.1; cc }.call(callcc
{ |c| c } ),
         lambda {|cc| print "* - #{cc}\n"; sleep 0.1; cc }.call(callcc
{ |c| c } ) )

Abinoam Jr.

On Tue, Nov 26, 2013 at 10:18 AM, Max Gonzih <gonzih@gmail.com> wrote:
> Hi guys, I was playing with continuations in Scheme and decided to
> port one puzzle from scheme to ruby. But it works in a different way.
>
> Here is my code and explatations:
> http://blog.gonzih.me/blog/2013/11/26/yin-yang-callcc-puzzle-in-ruby/
>
> Can someone explain why is this happening?
> Are there some limitations on how continuations can be used in ruby?
> Thanks!
>
> --
> Regards,
> Max
>

--
Regards,
Max