[QUIZ] Befunge (#184)

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?

···

On Nov 25, 2008, at 11:15 AM, brabuhr@gmail.com wrote:

On Tue, Nov 25, 2008 at 11:42 AM, Rob Biedenharn > <Rob@agileconsultingllc.com> 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 :wink:

%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

For those who want to play around I have extended Matthew's code with
some enhancements to allow
1) dynamically add lines with p
2) dump memory and stack -->nstruction ?d
3) show the stack --> ?s
4) Halt execution until <Enter> is pressed --> ?h
5) Enabled comment mode with ?= thus = this is ignored = to make
programs (even LOL) more readable

I found it quite helpful for debugging my Befunge programs
here it is, but the credit goes to Matthew of course.

http://pastie.org/324874

Enjoy
Robert

Because I never read the spec? :slight_smile:
(Though I did skim the wikipedia page.)

But, yeah, plus it would be much nicer to do them all at once (and
maybe throw % in too).

···

On Tue, Nov 25, 2008 at 4:30 PM, Matthew Moss <matt@moss.name> wrote:

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?

Update

http://pastie.org/324874

in h one can enter Befunge instructions for debugging
and the current instruction shows red in the dump (H for spaces) in
ANSI terminals.

Cool, I took a quick run at adding these couple of extensions to my
previous submission:

class Befunge93Extended < Befunge93
  define_method :"=" do
    move
    move until @memory[@position] == "="
  end

  define_method :"d" do
    puts
    25.times do |a|
      80.times do |b|
        print @memory[[b,a]].to_s
      end
      puts
    end
    s
  end

  define_method :"s" do
    puts
    puts "[#{@stack.join(":")}]"
  end
end

bf = Befunge93Extended.new

bf.memory = {
  [0,0] => "d", [1,0] => "v", [2,0] => " ", [3,0] => " ", [4,0] => " ",
  [0,1] => " ", [1,1] => "1", [2,1] => " ", [3,1] => " ", [4,1] => " ",
  [0,2] => " ", [1,2] => "2", [2,2] => " ", [3,2] => " ", [4,2] => " ",
  [0,3] => " ", [1,3] => "3", [2,3] => " ", [3,3] => " ", [4,3] => " ",
  [0,4] => " ", [1,4] => "s", [2,4] => " ", [3,4] => " ", [4,4] => " ",
  [0,5] => " ", [1,5] => "=", [2,5] => " ", [3,5] => " ", [4,5] => " ",
  [0,6] => ">", [1,6] => "@", [2,6] => "#", [3,6] => "<", [4,6] => " ",
  [0,7] => " ", [1,7] => "=", [2,7] => " ", [3,7] => ".", [4,7] => " ",
  [0,8] => " ", [1,8] => ">", [2,8] => ">", [3,8] => "^", [4,8] => " ",
}
bf.run #=> "program"\n\n\n[1:2:3]\n3

···

On Wed, Nov 26, 2008 at 4:41 PM, Robert Dober <robert.dober@gmail.com> wrote:

For those who want to play around I have extended Matthew's code with
some enhancements to allow
2) dump memory and stack -->nstruction ?d
3) show the stack --> ?s
5) Enabled comment mode with ?= thus = this is ignored = to make
programs (even LOL) more readable

http://gist.github.com/29673

···

On Wed, Nov 26, 2008 at 9:32 PM, <brabuhr@gmail.com> wrote:

On Wed, Nov 26, 2008 at 4:41 PM, Robert Dober <robert.dober@gmail.com> wrote:

For those who want to play around I have extended Matthew's code with
some enhancements

Cool, I took a quick run at adding these couple of extensions to my
previous submission:

Note that Befunge-93 was revised and extended a bit into Funge 98 (http://quadium.net/funge/spec98.html\) for those curious. I just got back from vacation, so I haven't compared these extensions with F98's and don't know if they're similar or not.

···

On Nov 26, 2008, at 8:54 PM, brabuhr@gmail.com wrote:

On Wed, Nov 26, 2008 at 9:32 PM, <brabuhr@gmail.com> wrote:

On Wed, Nov 26, 2008 at 4:41 PM, Robert Dober >> <robert.dober@gmail.com> wrote:

For those who want to play around I have extended Matthew's code with
some enhancements

Cool, I took a quick run at adding these couple of extensions to my
previous submission:

http://gist.github.com/29673

b.com/29673

Note that Befunge-93 was revised and extended a bit into Funge 98
(http://quadium.net/funge/spec98.html\) for those curious. I just got back
from vacation, so I haven't compared these extensions with F98's and don't
know if they're similar or not.

By all means check it out but I will share the little I have read
Funge98 is N-dimensional but I have only seen implementation details
for 3 dimensions.
The grid is not limited in size anymore... Befunge93 was an excellent
choice for the Quiz.
:slight_smile:
R.

···

On Sun, Nov 30, 2008 at 11:04 PM, Matthew Moss <matt@moss.name> wrote: