digitalmars.D - Lazy formatting
- Steven Schveighoffer (7/24) Jan 31 2021 I have often wanted a lazy formatting feature where you aren't
- Der (4/5) Jan 31 2021 Is this under serious consideration, or is it merely the
- Steven Schveighoffer (11/16) Jan 31 2021 Walter, Andrei, Atila and I are discussing for about 4 months. I have
- Paolo Invernizzi (6/25) Feb 02 2021 I would like to have a clear path to _increment_ it right now:
- Steven Schveighoffer (4/29) Feb 02 2021 That's a prime example of what a phobos v2 would allow. No code
- Paolo Invernizzi (3/17) Feb 02 2021 I underline that adding a new better method, is not a breakage ...
- Steven Schveighoffer (4/22) Feb 02 2021 Adding @nogc to a method that's overridable that was previously not
- Paolo Invernizzi (8/36) Feb 02 2021 I agree with you, that's why I simply suggested to _add_ a new
- Steven Schveighoffer (5/16) Feb 02 2021 OK, I was misunderstanding what you were saying (I may still not
- Paolo Invernizzi (7/27) Feb 03 2021 Sorry for my bad phrasing ... you are understanding it rightly :-P
- Steven Schveighoffer (7/15) Feb 03 2021 Not sure how to answer this. I only got involved 4 months ago. I can't
- Paolo Invernizzi (12/29) Feb 03 2021 I definitely understand that, don't worry.
- Kagamin (10/12) Feb 01 2021 I have a feeling recent DIPs are too detached from practice. If
- Adam D. Ruppe (9/14) Feb 01 2021 In ruby and php and stuff you can do
- rikki cattermole (3/5) Feb 01 2021 SQL is a good example which is not trivial due to anti-injection
- Kagamin (5/10) Feb 01 2021 Such queries usually appear in tests, where you work with trusted
- Steven Schveighoffer (15/28) Feb 01 2021 I'm not sure how you read this as "cuz other langs do it":
- Vladimir Panteleev (9/16) Feb 01 2021 Um, do you mean something like this?
- Steven Schveighoffer (6/24) Feb 01 2021 Oh nice, yes! That would actually work with the DIP as defined.
- Berni44 (14/18) Feb 02 2021 Most implementations in std.format produce the result from left
As a response to Andrei in DIP 1036 thread (as this is somewhat off topic):On 1/31/21 11:11 AM, Steven Schveighoffer wrote:I have often wanted a lazy formatting feature where you aren't allocating but it returns a string-able thing that can be used as an input range. I was surprised that phobos doesn't provide this. Would be really awesome to have, but I think possibly it means we need to reengineer the lower level. Probably a phobos 2.0 thing. -SteveThis is how I would do it: i"Hello, ${var.withFormat!"%45s"} world"; (where withFormat provides a toString overload that works with idup). No extra intermediate allocations necessary.I wonder if we can define a nice convention by the use of past tense vs. active. format!"%45s"(val) -> format using this spec the following values val.formatted!"%45s" -> value formatted with this spec We have just a bit of that with sort/sorted. Maybe flesh that up in phobos 2.0 :o).
Jan 31 2021
On Monday, 1 February 2021 at 00:25:42 UTC, Steven Schveighoffer wrote:Probably a phobos 2.0 thing.Is this under serious consideration, or is it merely the optimists' fervent dream.
Jan 31 2021
On 1/31/21 7:43 PM, Der wrote:On Monday, 1 February 2021 at 00:25:42 UTC, Steven Schveighoffer wrote:Walter, Andrei, Atila and I are discussing for about 4 months. I have only been involved since then, not sure what the plans were before that. This is not a facetious thing. We are trying to determine the best way to create a phobos v2 that does not break existing code. I don't know what it will look like, or if we can come up with something that is workable soon. But we are working on it. The thing that I'm most interested in is no autodecoding. But of course, with a place where we can create breaking changes that live in an "opt-in" space, it opens the door to a lot of other things that we may want to include. -SteveProbably a phobos 2.0 thing.Is this under serious consideration, or is it merely the optimists' fervent dream.
Jan 31 2021
On Monday, 1 February 2021 at 02:49:37 UTC, Steven Schveighoffer wrote:On 1/31/21 7:43 PM, Der wrote:I would like to have a clear path to _increment_ it right now: https://github.com/dlang/phobos/pull/6730 A clear policy and a final word simple additions like that would be great.On Monday, 1 February 2021 at 00:25:42 UTC, Steven Schveighoffer wrote:Walter, Andrei, Atila and I are discussing for about 4 months. I have only been involved since then, not sure what the plans were before that. This is not a facetious thing. We are trying to determine the best way to create a phobos v2 that does not break existing code. I don't know what it will look like, or if we can come up with something that is workable soon. But we are working on it. The thing that I'm most interested in is no autodecoding. But of course, with a place where we can create breaking changes that live in an "opt-in" space, it opens the door to a lot of other things that we may want to include. -SteveProbably a phobos 2.0 thing.Is this under serious consideration, or is it merely the optimists' fervent dream.
Feb 02 2021
On 2/2/21 3:51 AM, Paolo Invernizzi wrote:On Monday, 1 February 2021 at 02:49:37 UTC, Steven Schveighoffer wrote:That's a prime example of what a phobos v2 would allow. No code breakage, and provides a saner interface for future projects. -SteveOn 1/31/21 7:43 PM, Der wrote:I would like to have a clear path to _increment_ it right now: https://github.com/dlang/phobos/pull/6730 A clear policy and a final word simple additions like that would be great.On Monday, 1 February 2021 at 00:25:42 UTC, Steven Schveighoffer wrote:Walter, Andrei, Atila and I are discussing for about 4 months. I have only been involved since then, not sure what the plans were before that. This is not a facetious thing. We are trying to determine the best way to create a phobos v2 that does not break existing code. I don't know what it will look like, or if we can come up with something that is workable soon. But we are working on it. The thing that I'm most interested in is no autodecoding. But of course, with a place where we can create breaking changes that live in an "opt-in" space, it opens the door to a lot of other things that we may want to include.Probably a phobos 2.0 thing.Is this under serious consideration, or is it merely the optimists' fervent dream.
Feb 02 2021
On Tuesday, 2 February 2021 at 18:50:00 UTC, Steven Schveighoffer wrote:On 2/2/21 3:51 AM, Paolo Invernizzi wrote:I underline that adding a new better method, is not a breakage ...On Monday, 1 February 2021 at 02:49:37 UTC, Steven Schveighoffer wrote:That's a prime example of what a phobos v2 would allow. No code breakage, and provides a saner interface for future projects. -Steve[...]I would like to have a clear path to _increment_ it right now: https://github.com/dlang/phobos/pull/6730 A clear policy and a final word simple additions like that would be great.
Feb 02 2021
On 2/2/21 2:50 PM, Paolo Invernizzi wrote:On Tuesday, 2 February 2021 at 18:50:00 UTC, Steven Schveighoffer wrote:Adding nogc to a method that's overridable that was previously not nogc is breakage. That's the point of the folks in that review. -SteveOn 2/2/21 3:51 AM, Paolo Invernizzi wrote:I underline that adding a new better method, is not a breakage ...On Monday, 1 February 2021 at 02:49:37 UTC, Steven Schveighoffer wrote:That's a prime example of what a phobos v2 would allow. No code breakage, and provides a saner interface for future projects.[...]I would like to have a clear path to _increment_ it right now: https://github.com/dlang/phobos/pull/6730 A clear policy and a final word simple additions like that would be great.
Feb 02 2021
On Tuesday, 2 February 2021 at 20:03:18 UTC, Steven Schveighoffer wrote:On 2/2/21 2:50 PM, Paolo Invernizzi wrote:I agree with you, that's why I simply suggested to _add_ a new better method, and pointed also to precedents for that practise in Phobos ... But despite that, the point is NOT having a policy for such common improvements, and that why there was a call to authority ...On Tuesday, 2 February 2021 at 18:50:00 UTC, Steven Schveighoffer wrote:Adding nogc to a method that's overridable that was previously not nogc is breakage. That's the point of the folks in that review. -SteveOn 2/2/21 3:51 AM, Paolo Invernizzi wrote:I underline that adding a new better method, is not a breakage ...On Monday, 1 February 2021 at 02:49:37 UTC, Steven Schveighoffer wrote:That's a prime example of what a phobos v2 would allow. No code breakage, and provides a saner interface for future projects.[...]I would like to have a clear path to _increment_ it right now: https://github.com/dlang/phobos/pull/6730 A clear policy and a final word simple additions like that would be great.
Feb 02 2021
On 2/2/21 3:08 PM, Paolo Invernizzi wrote:On Tuesday, 2 February 2021 at 20:03:18 UTC, Steven Schveighoffer wrote:OK, I was misunderstanding what you were saying (I may still not understand it), but yes, we are trying to find a way to do these kinds of improvements. -SteveAdding nogc to a method that's overridable that was previously not nogc is breakage. That's the point of the folks in that review.I agree with you, that's why I simply suggested to _add_ a new better method, and pointed also to precedents for that practise in Phobos ... But despite that, the point is NOT having a policy for such common improvements, and that why there was a call to authority ...
Feb 02 2021
On Tuesday, 2 February 2021 at 20:33:03 UTC, Steven Schveighoffer wrote:On 2/2/21 3:08 PM, Paolo Invernizzi wrote:Sorry for my bad phrasing ... you are understanding it rightly :-POn Tuesday, 2 February 2021 at 20:03:18 UTC, Steven Schveighoffer wrote:OK, I was misunderstanding what you were saying (I may still not understand it),Adding nogc to a method that's overridable that was previously not nogc is breakage. That's the point of the folks in that review.I agree with you, that's why I simply suggested to _add_ a new better method, and pointed also to precedents for that practise in Phobos ... But despite that, the point is NOT having a policy for such common improvements, and that why there was a call to authority ...but yes, we are trying to find a way to do these kinds of improvements.Steven, it's a two years waiting for a trivial addition to an obsoleted (definition coming from the PR discussion) module. This thing start to smell more like "we don't care" that "we are carefully studying how hight to put the bar"
Feb 03 2021
On 2/3/21 4:03 AM, Paolo Invernizzi wrote:On Tuesday, 2 February 2021 at 20:33:03 UTC, Steven Schveighoffer wrote:Not sure how to answer this. I only got involved 4 months ago. I can't spend full time on it, I have an actual job. So I'm sparsely working on it. And it's important to prove that what we want to do is feasible and workable with our system of development. That's not an easy task, I've already hit some dead ends. -Stevebut yes, we are trying to find a way to do these kinds of improvements.Steven, it's a two years waiting for a trivial addition to an obsoleted (definition coming from the PR discussion) module. This thing start to smell more like "we don't care" that "we are carefully studying how hight to put the bar"
Feb 03 2021
On Wednesday, 3 February 2021 at 14:34:42 UTC, Steven Schveighoffer wrote:On 2/3/21 4:03 AM, Paolo Invernizzi wrote:I definitely understand that, don't worry.On Tuesday, 2 February 2021 at 20:33:03 UTC, Steven Schveighoffer wrote:Not sure how to answer this. I only got involved 4 months ago. I can't spend full time on it, I have an actual job. So I'm sparsely working on it.but yes, we are trying to find a way to do these kinds of improvements.Steven, it's a two years waiting for a trivial addition to an obsoleted (definition coming from the PR discussion) module. This thing start to smell more like "we don't care" that "we are carefully studying how hight to put the bar"And it's important to prove that what we want to do is feasible and workable with our system of development. That's not an easy task, I've already hit some dead ends.That's why defining policies and procedures is the way to go: they open up to scalability. That specific PR is just asking a very, very tiny and specific question. The answer to that can be generalised, and then can be generally applied to similar situation without posing the burden to reviewers. I will try to make this discussion constructive: I've seen Atila has commented the PR, and the PR was labeled "Andrej" ... I will ping again Atila on that, let's see if we can score a goal here.
Feb 03 2021
This is how I would do it: i"Hello, ${var.withFormat!"%45s"} world";I have a feeling recent DIPs are too detached from practice. If you read feature requests, people wanted interpolated strings in order to easily construct strings without tinkering. For ease of use. But the DIP's design rationale ended up being "because other languages have this". As design thus loses direction you end up designing an abstract silver bullet of interpolated strings without regard for practical needs. But we already have plenty of ways to tinker with string formatting. Who asked for one more way to do it? Almost all uses of interpolated strings are trivial ones i"I have ${n} apples".
Feb 01 2021
On Monday, 1 February 2021 at 13:31:48 UTC, Kagamin wrote:In ruby and php and stuff you can do "I have ${some_function()} apples". That's what withFormat is, simply a function you're calling in there which does a format. The DIP itself just allows for i"I have ${d_code_here} apples." and d_code_here can be a simple variable or it can be a function call or other fancy things. All the same feature.i"Hello, ${var.withFormat!"%45s"} world";I have a feeling recent DIPs are too detached from practice. [...] Who asked for one more way to do it? Almost all uses of interpolated strings are trivial ones i"I have ${n} apples".
Feb 01 2021
On 02/02/2021 2:31 AM, Kagamin wrote:Almost all uses of interpolated strings are trivial ones i"I have ${n} apples".SQL is a good example which is not trivial due to anti-injection techniques like escaping.
Feb 01 2021
On Monday, 1 February 2021 at 13:40:22 UTC, rikki cattermole wrote:On 02/02/2021 2:31 AM, Kagamin wrote:Such queries usually appear in tests, where you work with trusted data. In any case %45s means nothing for sql, and you can't use anything like that anyway.Almost all uses of interpolated strings are trivial ones i"I have ${n} apples".SQL is a good example which is not trivial due to anti-injection techniques like escaping.
Feb 01 2021
On 2/1/21 8:31 AM, Kagamin wrote:I'm not sure how you read this as "cuz other langs do it": https://github.com/dlang/DIPs/blob/344e00ee2d6683d61ee019d5ef6c1a0646570093/DIPs/DIP1036.md#rationale But in any case, the `withFormat` thing has nothing to do with the referenced DIP. That's why we're in a separate thread here. I have wanted in the past to just have a construct that says "format this value", but not have to decide where it goes. In other words, a lazy formatting. All of std.format expects a *destination* to put formatted data. I want the *source* to just be formatted data. It's actually a lower level abstraction than what is already in std.format, which could be built upon such a thing. Just an idea any way (and of course, it's relevant for string interpolation to anyone who might want a one-off format difference than the default). -SteveThis is how I would do it: i"Hello, ${var.withFormat!"%45s"} world";I have a feeling recent DIPs are too detached from practice. If you read feature requests, people wanted interpolated strings in order to easily construct strings without tinkering. For ease of use. But the DIP's design rationale ended up being "because other languages have this". As design thus loses direction you end up designing an abstract silver bullet of interpolated strings without regard for practical needs. But we already have plenty of ways to tinker with string formatting. Who asked for one more way to do it? Almost all uses of interpolated strings are trivial ones i"I have ${n} apples".
Feb 01 2021
On Monday, 1 February 2021 at 00:25:42 UTC, Steven Schveighoffer wrote:I have often wanted a lazy formatting feature where you aren't allocating but it returns a string-able thing that can be used as an input range. I was surprised that phobos doesn't provide this. Would be really awesome to have, but I think possibly it means we need to reengineer the lower level. Probably a phobos 2.0 thing.Um, do you mean something like this? https://github.com/CyberShadow/ae/blob/904d5b6ab7a15b3ecac499ef41bb40a88fd64e1e/utils/text/package.d#L47 assert(64.formatted!"%x".text == "40"); It's not an input range (I think emitting formatted strings as an input range without an intermediary buffer would be impractically difficult in general), but it does use the sink toString interface.
Feb 01 2021
On 2/1/21 10:28 AM, Vladimir Panteleev wrote:On Monday, 1 February 2021 at 00:25:42 UTC, Steven Schveighoffer wrote:Oh nice, yes! That would actually work with the DIP as defined. Yeah, you definitely need a buffer for formatting, it's somewhat possible to do with integers, but not as pleasant. But local buffers can be part of the type anyway (like a static array). -SteveI have often wanted a lazy formatting feature where you aren't allocating but it returns a string-able thing that can be used as an input range. I was surprised that phobos doesn't provide this. Would be really awesome to have, but I think possibly it means we need to reengineer the lower level. Probably a phobos 2.0 thing.Um, do you mean something like this? https://github.com/CyberShadow/ae/blob/904d5b6ab7a15b3ecac499ef41bb40a88fd64e1e/util /text/package.d#L47 assert(64.formatted!"%x".text == "40"); It's not an input range (I think emitting formatted strings as an input range without an intermediary buffer would be impractically difficult in general), but it does use the sink toString interface.
Feb 01 2021
On Monday, 1 February 2021 at 00:25:42 UTC, Steven Schveighoffer wrote:I have often wanted a lazy formatting feature where you aren't allocating but it returns a string-able thing that can be used as an input range. I was surprised that phobos doesn't provide this.Most implementations in std.format produce the result from left to right. It looks like this has been done on purpose, though I do not fully understand why. Aside from a few corner cases it's mainly formatting floating point numbers, that does not do so yet. Pondering whether it's possible to making the floatingpoint algorithms completely nogc I meanwhile think it might be possible to produce the results from left to right here too (with some local buffers and/or RYU printf or something similar). With that, it shouldn't be too difficult to put everything into a lazy range. (But still, it's a long road to go.) Anyway I wonder a little bit what use cases there are for such a range?
Feb 02 2021