From: Matthew Moss Date: 2008-11-26T06:30:50+09:00 Subject: Re: [QUIZ] Befunge (#184) On Nov 25, 2008, at 11:15 AM, brabuhr@gmail.com wrote: > 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 If you're going to fix the arg order of - and /, why wouldn't you do the same for + and *? Popping b first, then a, isn't a workaround; it's the correct method according to spec. Why make + and * an exception to that?