(A cheesy homepage for Justin Collins)
How are you?

I was messing around, seeing what silly things could be done using Brat, and I came up with several variations of this “How are you?” program.

Here’s one:
  How = {|x| p "How", x[0], x[1] }
  are = {|x| [" are "] + x }
  you? = ["you?"]
  I = {|x| p "I" , x[0], x[1], x[2] }
  am = {|x, y| x + y }
  fine = [" fine, "]
  thank = {|x| ["thank"] + x }
  you! = [" you!"]

  How are you?
  I am fine, thank you!

Pretty nifty, I thought.

Then I thought, “Well, I’m only using a question mark and an exclamation mark, I can probably replicate this in Ruby, too.”

This is the 2-minute direct translation I came up with:

  def How x
        print "How", x[0], x[1], "\n" 
  end

  def are x
        [" are "] + x
  end

  def you?
        ["you?"]
  end

  def I x
        print "I", x[0], x[1], x[2], "\n" 
  end

  def am x, y
        x + y
  end

  def fine
        [" fine, "]
  end

  def thank x
        ["thank"] + x
  end

  def you!
        [" you!"]
  end

  How are you?
  I am fine, (thank you!)

I was a little disappointed that Ruby has to be furtive about how it says thank you, but it doesn’t parse for me otherwise.


blog comments powered by Disqus