257-wrap brainfuck
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. The language had been introduced through l4m2's code-golf challenge.
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.
Dialect by 鳴神裁四点一号
In 2025 another user 鳴神裁四点一号 edited the post by pointing out for the case of finite length of input by clarifying actual semantics for looping commands, which is third difference from regular brainfuck language; if the reading command is immediately followed by a bracket (i.e. Programs [-]-.[
, [-]-.]
but not [-]-..]
nor <[
), the program counter enters the loop if the memory under the pointer is not -1, instead of comparing with 0.
With this feature, the following would be the actual cat program that would halt when there's finite input.
-.[.[-]-.]
History
l4m2 provided 256-wrap and and their corresponding 257-wrap brainfuck programs equivalents as in I/O and haltability behavior assuming those programs would receive infinite length of input stream (shown in edit order, ascending, some programs may be mistaken):
,. => -.. +[+++>+<]>. => +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++. ,[.,] => -.[.[-]-.] -[.-] => --[.-] ,[->++<]>. => -.[->+++>>>>>+<<<<<[>>>>>-<<<<]>[<]>>>>[<<<<<+>>>>>-]<<<<<-]>. ,+. => -.++[->+>+<<]>->[<]>. +[,.[-]+] => +[>-.[-]+] +[,.[-]+] => +[>-.+]
Implementation
- Tpaefawzen/257bf - Zig implementation. As of 2025-04-07, 鳴神裁四点一号's dialect is implemented.
External resources
- Convert 256-wrap brainfuck into 257-wrap brainfuck - Code Golf StackExchange; origin of this language. See also edit history.