fmt2.myr: Landed new string formatting code.
[Thread Prev] | [Thread Next]
[Date Prev] | [Date Next]
- Subject: fmt2.myr: Landed new string formatting code.
- From: Ori Bernstein <ori@xxxxxxxxxxxxxx>
- Date: Sun, 7 Jun 2015 09:57:10 -0700
- To: myrddin-dev@xxxxxxxxxxxxxx
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>
| Re: fmt2.myr: Landed new string formatting code. | Ryan Gonzalez <rymg19@xxxxxxxxx> |
- Next by Date: Re: fmt2.myr: Landed new string formatting code.
- Next by thread: Re: fmt2.myr: Landed new string formatting code.
- Index(es):