Previous: , Up: Printing   [Contents][Index]

14.17.2 printf

The printf statement gets a format string and, optionally, a list of values to print. It can be invoked using two alternative syntaxes, which are equivalent:

printf (fmt[, value…])
printf fmt[, value…]

The format string fmt is printed verbatim to the standard output, but for format tags which start with %. These format tags are interpreted especially. Most of the format tags “consume” one of the specified values. Every value in the list shall be described by a tag, or the compiler will signal an error. Likewise, values without a corresponding describing tag is an error. These tags are:


Print the argument as a string.


Print the argument as a signed integer of size bits. The last letter determines how the argument is printed.


Print the integer in decimal.


Print the integer in hexadecimal.


Print the integer in octal.


Print the integer in binary.


Print the integer as an ASCII character. This only works with 8 bit integers.


Same as %i, but for unsigned integers.


A shorter way to write %u8c.


Print the value printed representation of the argument, which can be of any type including complex types like arrays and structs. This is similar to the write operation available in many Lisp systems.

This tag supports an optional numerical argument (restricted to a single digit) that specifies the maximum depth level when printing structures. Example:

(poke) printf ("%1v\n", struct { s = struct { i = 10 },  l = 20L });
struct {s=struct {…},l=0x14L}

By default, the depth level is 0, which means no limit.

This tag also support an optional flag that specifies how the value is printed. The supported tags are F (for flat) and T (for tree). The default is flat. Example:

(poke) printf ("%Tv\n", struct { s = struct { i = 10 },  l = 20L });
struct {
  s=struct {
(poke) printf ("%Fv\n", struct { s = struct { i = 10 },  l = 20L });
struct {s=struct {i=0xa},l=0x14L}

This tag is mainly intended to be used in pretty-printers.

The following format tags do not consume arguments. They support emitting styled text using the libtextstyle approach of having styling classes that you can customize in a .css file.


Start the styling class with name classname. The class name cannot be empty.


End the last opened styling class. All styling classes should be ended before finishing the format string.

Note that styling classes can be nested, but all classes should be ended before finishing the format string.

If you use a name class, you can define how to style it in the .css file (poke installs and uses poke-default.css but you can set the POKE_STYLE environment variable to point to another css) like this:

.NAME { text-decoration: blink; color : pink; }


(poke) printf "This is a NAME: %<NAME:xxx%>"
This is a NAME: xxx
(poke) printf "Name: %<string:%s%> Age: %<integer:%i32d%>, "Jose", 39
Name: Jose Age: 39

Previous: , Up: Printing   [Contents][Index]