Formatter Reference
Produce Callable for given format specification
What it is #
Routines #
Signatures are reproduced from the documentation, including their declared return types. A routine listed here is part of the type's published interface; whether Raku++ implements it is a separate question, answered by the examples below.
method new #
method new($format --> Callable:D)
Returns Callable:D.
Returns a cached Callable object from a sprintf compatible format string. Will create a new Callable object if the given format string had not been seen before.
method CODE #
method CODE(--> Callable:D)
Returns Callable:D.
Returns an uncached Callable object from a sprintf compatible format string. Intended to be used in compile-time situations where caching is neither important nor wanted.
method AST #
method AST(--> RakuAST::Node:D)
Returns RakuAST::Node:D.
Returns a RakuAST representation of the Callable for the given sprintf compatible format string. Intended to be used for debugging.
Examples, run three ways #
Every example below comes from the official documentation, together with the output that documentation asserts. Each was then executed by Rakudo and by Raku++ when this page was built. Where the three agree, one result is shown; where they do not, all three are — because which of them is wrong is exactly the information worth having.
1 no-output · 2 ok
class Formatter { }Not executed: the documentation states no expected output for this example.
use v6.e.PREVIEW;
my &handle = Formatter.new("'%5s'");
say handle("foo"); # OUTPUT: «' foo'»' foo'
Documentation, Rakudo and Raku++ all agree.
use v6.e.PREVIEW;
my &zero5 = Formatter.new("%05d");
say zero5(42); # OUTPUT: «00042»00042
Documentation, Rakudo and Raku++ all agree.