257-wrap brainfuck

From Esolang
Jump to navigation Jump to search

257-wrap brainfuck is a brainfuck derivative published by Code Golf StackExchange user l4m2 in March 2022, which aims to make I/O work unambiguously even in the presence of end-of-file conditions.

Specification

257-wrap brainfuck has two differences from regular brainfuck, but is otherwise identical.

One difference is that the cells of the tape store integers modulo 257 – there are 257 possible values for each memory cell rather than the 256 that are seen in 8-bit brainfuck, with 256+1 wrapping around to 0 and 0-1 wrapping around to 256. (256 and -1 are equivalent, because they are equivalent modulo 257.)

The other difference is that the , and . commands are merged into a single command ., which has the following behaviour:

  • If the current tape cell's value is not -1, output that value as a byte;
  • If the current tape cell's value is -1, attempt to take one byte of input, and:
    • if successful, store that byte in the current tape cell;
    • if the input attempt fails due to an end-of-file condition, leave the current tape cell's value as -1.

The original specification of the language contains a grammar which disallows the use of a loop anywhere other than at the start of the program or the start of a loop body. This is likely to be a mistake in the specification rather than part of the language – it is contradicted by the sample programs and would prevent any loop ever being entered, making the control flow commands pointless.

External resources