I don't remember whether the following has been done in Ruby yet, but I
did it tonite. It turns Ruby numeric expressions into trees, and then
into Lisp prefix notation.

----------------8<----------------cut-here----------------8<----------------

class Quote
	class<<self; alias [] new; end
	def initialize(sym); @sym=sym; end
	def to_s; @sym.to_s; end
	def coerce(foo); [Quote[foo],self]; end
	[:+,:-,:*,:/].each {|op|
		eval "def #{op}(o); QuoteBin.new #{op.inspect}, self, o; end"
	}
end

class QuoteBin < Quote
	def initialize(o,l,r); @l,@o,@r=l,o,r; end
	def to_s; "(#{@o} #{@l} #{@r})"; end
end

----------------8<----------------cut-here----------------8<----------------

x = (2+Quote[:a]) * 3 * Quote[:b] - 2 * Quote[:a] / Quote[:c]
puts "and the answer is #{x}"
#==> and the answer is (- (* (* (+ 2 a) 3) b) (/ (* 2 a) c))



matju