## January 30, 2017

### Formatted String Output in RETRO 12

For simple output Retro provides a few functions:

  * putn
  * putc
  * puts

And so on. Each handles a specific type. The problem: displaying multiple things can get messy.

Consider:

    #1 putn $+ putc #2 putn
    $= putc #3 putn

With formatted output strings this can become:

    #3 #2 #1 '%n+%n=%n putsf

Formatting Options:

A \ denotes a control character. Currently this supports:

  * \n - newline
  * \t - tab

A % denotes a stack value to display. This currently supports:

  * %c - character
  * %s - string
  * %n - number

Anything else is displayed as the character.

````
{{
  :char fetch-next
    $n [ nl            ] case
    $t [ ASCII:HT putc ] case
    putc ;

  :obj fetch-next
    $c [ swap putc ] case
    $s [ swap puts ] case
    $n [ swap n:to-string puts ] case
    putc ;

  :display
    $\ [ char ] case
    $% [ obj  ] case
    putc ;
---reveal---
  :putsf
    [ repeat
        fetch-next 0; display
      again
    ] call drop ;
}}
````