ebf icon indicating copy to clipboard operation
ebf copied to clipboard

Procedural brainfuck

Open ForNeVeR opened this issue 10 years ago • 4 comments

There is a brainfuck extension known as "procedural brainfuck". It adds two additional commands/concepts:

  1. ( and ) will define a piece of code as a procedure coded with the number in the current memory cell.
  2. : will call a procedure defined with a number in the current memory cell.

It helps to create more functional and interesting programs solving real-world problems with ease.

For example, this simple code defines a procedure with number 1 and calls it:

[+]+  ; now current = 1
(+++) ; define a procedure that will increment cell by 3
[+]+  ; clean up the cell and set it to 1 again
:     ; call the procedure
      ; now current = 4

ForNeVeR avatar Oct 31 '15 10:10 ForNeVeR

Good proposal! Thanks!

I need to think how this will actually look after the transpilation...

rexim avatar Oct 31 '15 10:10 rexim

@ForNeVeR [+]+ is rather strange way to clean a cell and set it to 1. Are you sure you didn't mean [-]+?

rexim avatar Feb 10 '16 05:02 rexim

They are completely equivalent in all of the modern BF dialects, so yes, I am sure. Optimizing BF compiler (yes there is a such thing) should simply replace [+] and [-] with setting the cell value to zero.

Also, both of these instructions will execute in equal time (and very slowly) if the cell initially already was set to zero. Maybe even -[+] could be used as a common case optimization.

ForNeVeR avatar Feb 10 '16 05:02 ForNeVeR

@ForNeVeR ok, thanks for the explanation

rexim avatar Feb 10 '16 06:02 rexim