Wanted: Format character for source code literal
Berni44
someone at somemail.com
Wed May 5 08:46:05 UTC 2021
On Tuesday, 4 May 2021 at 18:02:50 UTC, Q. Schroll wrote:
> So you're stuck between a rock and a hard place: Give `%D`
> preference over custom format specifiers rendering those that
> use `%D` invalid or let `%D` do its custom stuff if
> *potentially* supported rendering `%D` useless in generic code
> where most of its use-cases would lie.
I fear, I can't follow you. Seems like I don't get your point.
Maybe you can give an example?
>> In my opinion, the main idea behind this formatting routines
>> is, to have a simple and short way for formatting output. We
>> could use your idea for every other format character too,
>> like: `format("%s = %s", character('𝜋'),
>> scientificFloatingPoint(3.14))`. We don't do that, because
>> it's more convenient to write `format("%c = %e", '𝜋', 3.14)`.
>
> Yes, you could. But you could use format specifiers like
> `%-3.8f` *without losses* to get to the same result.
??? Again I'm stuck. What has `%-3.8f` with what I wrote above to
do?
> And that's *the* difference between introducing a format
> specifier character that should have generic meaning and
> introducing, well, anything else. There was no problem
> introducing separators like `%,3d` and neither would there be a
> problem introducing `%y` for `int` or `double` (whatever it
> does), or, for a concrete example, `%S` for `bool` to return
> `TRUE` instead of `true`.
>
> The problem is introducing *generic* format specifier
> *characters*.
What is the difference between "generic" (which as far as I
understand you oppose) and adding `%D` for bool, integers,
floats, characters, strings, arrays and AAs (which you sound as
being OK with, and which is, what I plan to do)?
> What we could do is special casing `%$` to mean what you want.
> Currently, no matter what type you're formatting, `%$` is an
> error in `FormatSpec`. You can give it semantics, no problem,
> including one that ignores custom formatting. Even better, `%$`
> looks like it's a special case and not some odd-but-legal
> custom specifier.
Using `$` would cause real troubles, because it's already used
for positional arguments. What would `format("%1$d", 'a');` be
supposed to produce? `'a'd` or `97`?
> Changing the meaning of `%D` begs for trouble.
`%D` has currently no meaning, so we cannot change it; we can
just add it.
I hope, we can figure this out somehow - I sense, that you've got
an important point, but I don't understand it. Seems like we are
talking past each other.
More information about the Digitalmars-d
mailing list