From: brabuhr@... Date: 2008-11-26T02:15:45+09:00 Subject: Re: [QUIZ] Befunge (#184) On Tue, Nov 25, 2008 at 11:42 AM, Rob Biedenharn wrote: > On Nov 25, 2008, at 11:07 AM, brabuhr@gmail.com wrote: >> almost entirely untested) implementation built around define_method: >> >> bf.run #=> 3 > > Seems like this program is: > > 1 1 + 2 3 + - . > > Which seems to be -3, not 3. I think you have your args out of order. Look > at how the non-commutative ops are defined. Yeah, that would be part of the entirely untested stuff ;-) %w{ + * }.each do |o| define_method :"#{o}" do a, b = @stack.pop, @stack.pop @stack.push a.send(:"#{o}", b) end end %w{ - / }.each do |o| define_method :"#{o}" do b, a = @stack.pop, @stack.pop @stack.push a.send(:"#{o}", b) end end or, maybe some would prefer: %w{ - / }.each do |o| define_method :"#{o}" do a, b = @stack.pop, @stack.pop @stack.push b.send(:"#{o}", a) end end