[PATCH 0/2] Use ? in format specifiers
[Thread Prev] | [Thread Next]
[Date Prev] | [Date Next]
- Subject: [PATCH 0/2] Use ? in format specifiers
- From: "S. Gilles" <sgilles@xxxxxxx>
- Reply-to: myrddin-dev@xxxxxxxxxxxxxx
- Date: Sat, 23 Nov 2019 17:29:02 -0500
- To: "myrddin-dev" <myrddin-dev@xxxxxxxxxxxxxx>
- Cc: "S. Gilles" <sgilles@xxxxxxx>
As discussed on IRC, I'd like to print/fmt things to some fixed width,
but I don't know the width at compile time, only at runtime. This allows
passing '?' as an argument to any format parameter. When processed (in
sbfmtv), a ? means "Pull the next thing out of ap, turn it into a
string, and use THAT as the argument". So you can write things like
std.put("{w=?}\n", 99, "foo")
std.put("{w=?}\n", some_int_var, "bar")
or even (since everything is string-ified and perhaps unparsed)
std.put("{w=?}\n", "99", "foo")
You can't use installed formatters to parse the ?-params, though, so
something like
std.put("{w=?}\n", `Some_complicated_structure(99,"a",`XY), "foo")
probably won't fly.
Possible objections:
- It feels inefficient to convert 99 into "99", then parse it back as
the number 99. This is the price we pay for params being a simple
(byte[:], byte[:])[:], and I think it's a reasonable price.
- The temps array (of constructed byte[:]s that we must free before
returning) feels a bit hacky. As has also been discussed a little on
IRC, this really feels like the place where `auto' could shine, if
the semantics were tweaked a bit.
- The only current known use-case for this is variable-width padding;
perhaps it's not worth losing 1:1 {}:argument counting for that?
- ?
S. Gilles (2):
Convert lib/test/fmt.myr to use testr
Allow formatting arguments from variables
lib/std/fmt.myr | 32 ++++++--
lib/std/test/fmt.myr | 190 +++++++++++++++++++++++++------------------
test/matchctup.myr | 32 ++++++++
3 files changed, 172 insertions(+), 82 deletions(-)
create mode 100644 test/matchctup.myr
--
2.24.0
| [PATCH 1/2] Convert lib/test/fmt.myr to use testr | "S. Gilles" <sgilles@xxxxxxx> |
| [PATCH 2/2] Allow formatting arguments from variables | "S. Gilles" <sgilles@xxxxxxx> |
- Next by Date: [PATCH 1/2] Convert lib/test/fmt.myr to use testr
- Next by thread: [PATCH 1/2] Convert lib/test/fmt.myr to use testr
- Index(es):