digitalmars.D.learn - array append result type
- John Colvin (5/5) Oct 06 2014 string a;
- monarch_dodra (9/14) Oct 06 2014 *Ideally*, I'd have said "it returns char[], so that you can
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (19/30) Oct 06 2014 Array concatenation should be considered pure because it is the
- Steven Schveighoffer (8/13) Oct 06 2014 It really should be whatever you want. a ~ b is going to generate a
- monarch_dodra (4/8) Oct 06 2014 I didn't read the whole thing, but wouldn't purity be a major
- Steven Schveighoffer (6/14) Oct 06 2014 Of course! It was immediately what I thought of when purity = unique was...
string a; char[] b; pragma(msg, typeof(a ~ b)); // char[] why not string? What are the rules that determine this?
Oct 06 2014
On Monday, 6 October 2014 at 11:28:16 UTC, John Colvin wrote:string a; char[] b; pragma(msg, typeof(a ~ b)); // char[] why not string? What are the rules that determine this?*Ideally*, I'd have said "it returns char[], so that you can chose via purity". However, it's not pure, so that argument doesn't hold. That said, casting to immutable is safe provided you never actually mutate. The reverse isn't true. To answer the question directly though, I don't know what the rules are. I'd guess they are mostly "whatever druntime implemented" though...
Oct 06 2014
On 10/06/2014 04:40 AM, monarch_dodra wrote:On Monday, 6 October 2014 at 11:28:16 UTC, John Colvin wrote:Array concatenation should be considered pure because it is the equivalent of the following function, which currently works: pure char[] cat(string a, const(char)[] b) { return a ~ b; } void main() { string a; char[] b; char[] c = cat(a, b); // works string s = cat(a, b); // works } http://dlang.org/function.html#pure-functions We should bring the above function and the ~ operator in line with each other. I haven't followed the discussions on GC usage in purity closely but if 'new' is allowed, GC allocations should be allowed as well. Alistring a; char[] b; pragma(msg, typeof(a ~ b)); // char[] why not string? What are the rules that determine this?*Ideally*, I'd have said "it returns char[], so that you can chose via purity". However, it's not pure, so that argument doesn't hold.
Oct 06 2014
On 10/6/14 7:28 AM, John Colvin wrote:string a; char[] b; pragma(msg, typeof(a ~ b)); // char[] why not string?It really should be whatever you want. a ~ b is going to generate a completely unique independent copy of a and b.What are the rules that determine this?Not sure. I would have expected at least one of a ~ b or b ~ a to be string, but both generate char[]. I filed this ER ages ago: https://issues.dlang.org/show_bug.cgi?id=1654 Not sure if anyone has it on their radar at this point. -Steve
Oct 06 2014
On Monday, 6 October 2014 at 16:38:37 UTC, Steven Schveighoffer wrote:I filed this ER ages ago: https://issues.dlang.org/show_bug.cgi?id=1654 Not sure if anyone has it on their radar at this point. -SteveI didn't read the whole thing, but wouldn't purity be a major game changer for 1654?
Oct 06 2014
On 10/6/14 1:01 PM, monarch_dodra wrote:On Monday, 6 October 2014 at 16:38:37 UTC, Steven Schveighoffer wrote:Of course! It was immediately what I thought of when purity = unique was introduced (that and dup/idup). This aspect has not been mentioned on the thread, but that issue is really old. -SteveI filed this ER ages ago: https://issues.dlang.org/show_bug.cgi?id=1654 Not sure if anyone has it on their radar at this point. -SteveI didn't read the whole thing, but wouldn't purity be a major game changer for 1654?
Oct 06 2014