Eigenstate: myrddin-dev mailing list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

fmt2.myr: Landed new string formatting code.


I've got a new version of std.fmt() which uses the generated type info
to know the types of its arguments, and which can support custom format
functions.

Format strings are now very different. '%' is the value placeholder.
There are no other specifiers. Formatting options are passed via the
'{opts}' after the placeholder. '%%' escapes the '%', so that a single
'%' is printed. {} is the empty parameter list, and needs to be passed
if you are printing a { immediately after a placeholder. Examples:

    std.f2put("x=%\n", 123)
        prints "x=123"

    std.f2put("x=%{x}\n", 255)
        prints "x=ff"

    std.f2put("x=%{}{asdf}\n", 123)
        prints "x=123{asdf}"

    std.f2put("x=%, %\n", 255)
        Kills your program because your arg list doesn't match the
        format string (there are too few args)

    std.f2put("x=%\n", 123, 456)
        Kills your program because your arg list doesn't match the
        format string (there are too many args)


It hasn't replaced std.fmt() yet, and is accessible via the f2fmt()
functions, but I intend to kill off the current std.fmt as soon as
I verify that this is working well on plan9.

Code is here:
    http://git.eigenstate.org/ori/mc.git/tree/libstd/fmt2.myr

It depends on the new type introspection api:
    http://git.eigenstate.org/ori/mc.git/tree/libstd/introspect.myr

API design reviews would be welcome. I'm not sure how happy I am
with the introspection API, although I do like that it lets me
look at stuff without descending into it, and without needing any
heap allocations.

-- 
Ori Bernstein <ori@xxxxxxxxxxxxxx>

Follow-Ups:
Re: fmt2.myr: Landed new string formatting code.Ryan Gonzalez <rymg19@xxxxxxxxx>