Created
May 5, 2010 08:38
-
-
Save jeena/390539 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env ruby -wKU | |
module Kernel | |
alias λ proc | |
def ∑ *terms | |
terms.inject { |sum, term| sum + term } | |
end | |
def √ term | |
Math.sqrt term | |
end | |
end | |
def say_formula text, a, b, formula | |
puts "#{text}#{formula.call(a, b)}" | |
end | |
a, b = 2, 3 | |
say_formula "Pythagoras says if a is #{a} and b is #{b} then c is ", a, b, λ {|a,b| √ a*a + b*b } | |
say_formula "I say if a is #{a} and b is #{b} then a + b = ", a, b, λ {|a,b| ∑ a, b } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment