Forum: Ruby uestion about ruby continuations.

D0fce0d0c982f0ed2301ce51f7715153?d=identicon&s=25 Max Gonzih (Guest)
on 2013-11-26 14:19
(Received via mailing list)
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:

Can someone explain why is this happening?
Are there some limitations on how continuations can be used in ruby?
09a32175057418748822c587ac08c429?d=identicon&s=25 Abinoam Jr. (abinoampraxedes_m)
on 2013-12-06 06:31
(Received via mailing list)
Hi Max Gonzih,


lambda do |yin, yang| yang {|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:
2) An explanation of Scheme "let" here:

Let is only syntactic sugar for an underlying lambda application:

((lambda (var1 var2 ... varn)
 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

# "Debug" version
lambda do |yin, yang| yang {|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.
D0fce0d0c982f0ed2301ce51f7715153?d=identicon&s=25 Max Gonzih (Guest)
on 2013-12-06 08:45
(Received via mailing list)
Now I get it. Great job, thank you!
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.