On Tuesday, 14 December 2021 at 13:40:02 UTC, deadalnix wrote:
>If we are honest, it probably similar at this point.
Learn
from each other and copy
from each other.
December 14, 2021 Re: String interpolation, after a healthy debate on discord | ||||
---|---|---|---|---|
| ||||
Posted in reply to deadalnix | On Tuesday, 14 December 2021 at 13:40:02 UTC, deadalnix wrote: >If we are honest, it probably similar at this point.
|
December 14, 2021 Re: String interpolation, after a healthy debate on discord | ||||
---|---|---|---|---|
| ||||
Posted in reply to WebFreak001 | On Thursday, 9 December 2021 at 21:06:11 UTC, WebFreak001 wrote: >We had an argument on the discord about the YAIDIP proposal and a To a give another POV, from a polyglot background, I'd say there is a statement in the YAIDIP which is incorrect and somewhat skews the rest of the argument:
Surely the simplest use case, and most likely to be encountered, is simply to build a well formatted string from a blend of string literals and local variables:
where s would be of string type. I use interpolated strings in numerous languages and I do so to present a clear expression to the reading developer of the intended format of the final string, and to keep the code tidy. In fact, I code like above specifically to avoid passing messy expressions as arguments to a following function call. I can see the power and attraction of the proposed design, but it has to be weighed against a syntax that satisfies the principle of least astonishment, as also identified in the same DIP. I'm also thinking that if tuples were more fully integrated and rationalised in the language then the benefits offered by this DIP regarding passing argument lists to string handling functions could be achieved in some other way using syntactically convenient unpacking of tuples into argument lists, but it's been a long time now since I used D in anger so if this part of my argument is just noise then... ignore it :-) |
December 14, 2021 Re: String interpolation, after a healthy debate on discord | ||||
---|---|---|---|---|
| ||||
Posted in reply to WebFreak001 | On 12/14/21 6:15 AM, WebFreak001 wrote: >On Tuesday, 14 December 2021 at 11:02:58 UTC, Ogi wrote: >On Tuesday, 14 December 2021 at 09:35:27 UTC, WebFreak001 wrote: >no this proposal does not suggest moving any functionality into the compiler. It suggests to add the istrings (tuples with header) as described in the YAIDIP and have special function calling syntax ( I was referring to YAIDIP. According to it, istring should be allowed in pramga(msg) and mixin do not need implementations of
assert would need some implementation of runtime output. But it's already in the library with ah right you mean for the built-in istring usage in the compiler it needs to be implemented. I don't think it's such a big problem though, as the phobos implementation would also just be: (a little simplified)
The DIP is designed specifically to work with As for the specialized call syntax, I don't think we need it. As for implementing some -Steve |
December 14, 2021 Re: String interpolation, after a healthy debate on discord | ||||
---|---|---|---|---|
| ||||
Posted in reply to rikki cattermole | On Tuesday, 14 December 2021 at 14:01:56 UTC, rikki cattermole wrote: >On 10/12/2021 10:06 AM, WebFreak001 wrote: >What do you think? Would this be essential for interpolated string adoption in user code or be useless? I am against it. Due to it marrying a memory management+formatting strategy to the language. One way to do this is to support what do you mean with this? Memory management isn't part of the language or the proposal here (you need to use std.conv : So if you want to get data from your database?
That could pass it in as an interpolated string. However, that could be extremely confusing to the user as this is a function call, which takes a string... yet its actually something very different. Like why doesn't adding the brackets allow for that to work? ext. ext. this is the same as JS template literal syntax - it's another way of calling a function. Given how different it looks from regular function calls, I don't think you would be very confused. The compiler would also tell you that you are trying to pass a string to a function that checks for an istring. Just like currently One reason I would like this pattern even though I don't think we should ever have it is so that I can have hex strings back. Super useful during code generation and table generation for large data sets (now days I've found that std.base64 does an excellent job at this, even with a little bit of fluff). ubyte[] data = hex"AABBCC"; // ok I was thinking about this as well - it would work but would run at runtime. I'm not a fan of using it just for static data and think |
December 14, 2021 Re: String interpolation, after a healthy debate on discord | ||||
---|---|---|---|---|
| ||||
Posted in reply to WebFreak001 | On Tuesday, 14 December 2021 at 15:58:21 UTC, WebFreak001 wrote:
> I was thinking about this as well - it would work but would run at runtime.
Not necessarily - the string literal portions ARE available at compile time and the function could just choose to return those as a ctfe calculation.
That's one of the deeper layers of good about this dip.
|
December 14, 2021 Re: String interpolation, after a healthy debate on discord | ||||
---|---|---|---|---|
| ||||
Posted in reply to WebFreak001 | On Tuesday, 14 December 2021 at 15:58:21 UTC, WebFreak001 wrote: > >ubyte[] data = hex"AABBCC"; // ok I was thinking about this as well - it would work but would run at runtime. I'm not a fan of using it just for static data and think Then why isn't |
December 14, 2021 Re: String interpolation, after a healthy debate on discord | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel N | On Tuesday, 14 December 2021 at 16:04:58 UTC, Daniel N wrote: >On Tuesday, 14 December 2021 at 15:58:21 UTC, WebFreak001 wrote: > >ubyte[] data = hex"AABBCC"; // ok I was thinking about this as well - it would work but would run at runtime. I'm not a fan of using it just for static data and think Then why isn't
expands to
that wouldn't work because name is a runtime variable and you are trying to use it as a template parameter here. You would need to do or as this post suggested a new calling syntax that extends to that: |
December 14, 2021 Re: String interpolation, after a healthy debate on discord | ||||
---|---|---|---|---|
| ||||
Posted in reply to rumbu | On Tuesday, 14 December 2021 at 12:29:57 UTC, rumbu wrote: >We have 100 keywords in D and many of them have multiple meanings (scope, static, if, is, in, out, const, do, enum, return) static mostly comes from C++. C++ is not necessary a complex language, STL usage and associated idioms makes it complex. If you compare the spec for the subset of D which C++ can implement, I think you will find it is more complex than the spec for D. References and lambdas for example. When designing a language, minimizing the set of keywords is not necessarily a good goal, the opposite is often true. You want code to look obvious. There are often tricks to reuse keywords, I'm glad D generally doesn't do that. |
December 14, 2021 Re: String interpolation, after a healthy debate on discord | ||||
---|---|---|---|---|
| ||||
Posted in reply to WebFreak001 | On Tuesday, 14 December 2021 at 16:15:28 UTC, WebFreak001 wrote: >
that wouldn't work because name is a runtime variable and you are trying to use it as a template parameter here. I assumed it works with alias/variadic params...?
|
December 14, 2021 Re: String interpolation, after a healthy debate on discord | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel N | On Tuesday, 14 December 2021 at 20:07:43 UTC, Daniel N wrote: >On Tuesday, 14 December 2021 at 16:15:28 UTC, WebFreak001 wrote: >
that wouldn't work because name is a runtime variable and you are trying to use it as a template parameter here. I assumed it works with alias/variadic params...?
It works for variables, but not arbitrary expressions. For example, if you wrote
...then you would get an error:
|