[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: fmt2.myr: Landed new string formatting code.
- Subject: Re: fmt2.myr: Landed new string formatting code.
- From: Ori Bernstein <ori@xxxxxxxxxxxxxx>
- Date: Sun, 7 Jun 2015 13:30:46 -0700
- To: Ryan Gonzalez <rymg19@xxxxxxxxx>
- Cc: myrddin-dev@xxxxxxxxxxxxxx
Braces are only for specifying options. % is the placeholder.
std.fmt("% % %", 1, 2, 255) => "1, 2, 255"
std.fmt("% % %{x}", 1, 2, 255) => "1, 2, ff"
On Sun, 07 Jun 2015 12:56:35 -0500
Ryan Gonzalez <rymg19@xxxxxxxxx> wrote:
> Looks neat! One thing: it seems weird to specify a percent *and* the braces. Python uses no percent with the .format function; it's just the braces.
>
> I can test it on Plan 9 once I can figure out how to "git pull" with an rc script I found...
>
> Curiosity: how to you commit changes to the repo from Plan 9?
>
>
> On June 7, 2015 11:57:10 AM CDT, Ori Bernstein <ori@xxxxxxxxxxxxxx> wrote:
> >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>
>
> --
> Sent from my Android device with K-9 Mail. Please excuse my brevity.
--
Ori Bernstein <ori@xxxxxxxxxxxxxx>