Re: fmt2.myr: Landed new string formatting code.
[Thread Prev] | [Thread Next]
- Subject: Re: fmt2.myr: Landed new string formatting code.
- From: Ori Bernstein <ori@xxxxxxxxxxxxxx>
- Date: Mon, 15 Jun 2015 09:21:26 -0700
- To: Ori Bernstein <ori@xxxxxxxxxxxxxx>
- Cc: Ryan Gonzalez <rymg19@xxxxxxxxx>, myrddin-dev@xxxxxxxxxxxxxx
And I moved to '{' and '}'. There are still a few questions in my mind about escaping -- right now I use '{{' and '}}', but it's a bit ugly/confusing. Still, {} works better for a semi-common usecase: std.fmt("%%%", prefix, sep, suffix) will fail with '%' because the first '%%' will be taken as a literal '%', but it's fine with {}: std.fmt("{}{}{}", prefix, sep, suffix) On Sun, 7 Jun 2015 14:36:38 -0700, Ori Bernstein <ori@xxxxxxxxxxxxxx> wrote: > Ah, I see what you mean; I don't feel strongly about it -- if you want to > submit a patch to change it, then it shouldn't be hard. > > On Sun, 07 Jun 2015 16:13:51 -0500 > Ryan Gonzalez <rymg19@xxxxxxxxx> wrote: > > > Yeah, I just found it odd. In Python, the braces are the placeholder *and* the options list. > > > > > > On June 7, 2015 3:30:46 PM CDT, Ori Bernstein <ori@xxxxxxxxxxxxxx> wrote: > > >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> > > > > -- > > Sent from my Android device with K-9 Mail. Please excuse my brevity. > > > -- > Ori Bernstein <ori@xxxxxxxxxxxxxx> > -- Ori Bernstein
fmt2.myr: Landed new string formatting code. | Ori Bernstein <ori@xxxxxxxxxxxxxx> |
Re: fmt2.myr: Landed new string formatting code. | Ryan Gonzalez <rymg19@xxxxxxxxx> |
Re: fmt2.myr: Landed new string formatting code. | Ori Bernstein <ori@xxxxxxxxxxxxxx> |
Re: fmt2.myr: Landed new string formatting code. | Ryan Gonzalez <rymg19@xxxxxxxxx> |
Re: fmt2.myr: Landed new string formatting code. | Ori Bernstein <ori@xxxxxxxxxxxxxx> |
- Prev by Date: Re: fmt2.myr: Landed new string formatting code.
- Next by Date: Build errors. Again.
- Previous by thread: Re: fmt2.myr: Landed new string formatting code.
- Next by thread: Build errors. Again.
- Index(es):