brainfuck for humans

From Esolang
Jump to navigation Jump to search
Not to be confused with brainfuck 4 humans.

brainfuck 4 humans is a perfectly good esolang, with perfectly good syntax, but I think we can make it easier to read, y’know?

Syntax

Brainfuck for humans has a similar syntax to brainfuck 4 humans, with the important addition of enumerated motions, for example: left 3; is equivalent to left;left;left; in brainfuck for humans, the syntax list is as follows:

(For this example we may assume m is the memory pointer and [m] is a dereference from m, otherwise C like syntax may be assumed)

  1. right x ; equiv to m += x
  2. left x ; equiv to m -= x
  3. zero ; [m] = 0
  4. add x ; equiv to [m] += x
  5. subtract x ; equiv to [m] -= x
  6. input ; equiv to bf(“,”)
  7. output ; equiv to bf(“.”)
  8. loop (s) ; while ([m]) { s }
  9. clear ; loop (subtract 1;);
  10. set x ; clear; add x;
  11. set ‘x’ ; set ord(x)
  12. string “x”; for(I=0; I<strlen(“x”); I++) { set “x”[I]; right 1; }
  13. read ; file=fopen(m, “r”); fread(m, 1, file_len, file);
  14. write ; file=fopen(m, “w”); fwrite(m+strlen(m)+1,1,strlen(m+strlen(m)+1),file);
  15. remark [ x ] ; /* x */

To put multiple statements on the same line use the keyword and or the token &, a line should end with ..

Hello World

The Hello World follows:

zero and right 1.
string "Hello World!" and add 10.
right 1 zero.
left 1 and loop (left 1) and right 1.
write.

Which simply embeds a string with a newline at the end with a null terminator at the beginning and end. So that we can go to the beginning of the string by making sure we are inside of it, and then using loop (left 1) and right 1. to go to the left until we reach the introductory NUL and then move forwards to the first character in the string.