Created
January 26, 2012 03:48
-
-
Save sdeming/1680865 to your computer and use it in GitHub Desktop.
Use callcc for non-recursive factorials.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'continuation' | |
class FactorialsInCC | |
def fact(n) | |
factorial = 1 | |
callcc { |fact_jmp| @fact_jmp = fact_jmp } | |
factorial *= n | |
n -= 1 | |
@fact_jmp.call if n > 1 | |
factorial | |
end | |
end | |
puts FactorialsInCC.new.fact(ARGV[0].to_i) |
Haha, i'm just busting your balls. It really is cool stuff. Have you done anything useful with it yet?
Hah, not yet. At least not in Ruby. In Ruby, I think callcc is a solution looking for a problem. A good use case may not actually exist.
That's exactly what I said!!
Did not! Er, where?
I told you it was a trap!
On Thu, Jan 26, 2012 at 10:41 PM, Scott Deming < ***@***.*** > wrote:
Did not! Er, where?
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/1680865
##
Justin Mazzi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It gets really cool when you start passing the continuations around.