Ilmari Heikkinen
12/15/2005 2:55:00 PM
# A bit of fun to while away a boring afternoonclass Fixnum def prev self - 1 endenddef add a, b return a if b.zero? if b > 0 add a.succ, b.prev else add a.prev, b.succ endenddef leval(args) return args unless args.is_a? Array args.map!{|a| if a.is_a? Array leval a else a end } op, *args = args functions[op][args]enddef functions { :if => lambda{|args| if leval(args.first) then args[1] else args[2] end }, :zero? => lambda{|args| not (args.first > 0 or args.first < 0) }, :+ => lambda{|args| args.inject{|s,i| add s, i}}, :- => lambda{|args| args.inject{|s,i| add s, -i}} }endp leval([[:if, [:zero?, 0], :+, :-], 3,4])