Close

Code: Indentation

A project log for reprint: modern printf

reprint is printf redone with decades of hindsight, revamping the semantics and syntax to make a function worthy of Hello World.

analog-twoAnalog Two 04/03/2016 at 13:050 Comments

A common pattern in output is to indent a line based on its depth in a hierarchy (i.e., JSON or XML, or function depth when debugging). Though the output is the same, the method is different between reprint and printf:

/* Indentation with N spaces on reprint and printf */
int N = 10;

reprintf("\f=ep", N, ' ');

printf("%*s", N, "");
  1. \f: Formatted output field header
  2. =: Store the corresponding integer in the '=' register (register 4).
  3. ep: The data input type is a character, 8 bits.

In reprint, numeric parameters are specified by the user as loading register values (much like a microprocessor). The numeric value does not have any meaning without a corresponding input type. So when reprint parses 'e', the meaning of the register is understood to be character repetition.

Discussions