October 30, 2012 [Issue 8910] Static arrays, dynamic arrays and std.array.join | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Cousens | http://d.puremagic.com/issues/show_bug.cgi?id=8910 --- Comment #10 from Daniel Cousens <daniel350@bigpond.com> 2012-10-30 14:04:16 PDT --- (In reply to comment #9) > > Frankly thats a terrible alternative. Perhaps static array specialisations are in order then; assuming current implementations can't be modified to suit. > > So, you think that copying a static array is a good idea? Because that's what on overload for a static array would do. And all that overload could do would be to slice the static array and pass it to the normal overload (because static arrays are _not_ ranges and _cannot_ be, because you can't pop any of their elements off), which would lead to the slice being completely invalid once the function returned, meaning that the result would be completely unsafe and invalid. So no, that wouldn't work. I do think it is a good idea, no, but that was the "clearest" solution... second to that proposed by Timon: map!(c => c[])(cs[]).join(","); But if what you say is set in stone, then there is no point taking it further. Maybe other than the fact putting something in the documentation/compiler warning so that the error message that is given is not so confusing to those coming from other languages. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 30, 2012 [Issue 8910] Static arrays, dynamic arrays and std.array.join | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Cousens | http://d.puremagic.com/issues/show_bug.cgi?id=8910 --- Comment #11 from Daniel Cousens <daniel350@bigpond.com> 2012-10-30 14:05:00 PDT --- (In reply to comment #9) > > Frankly thats a terrible alternative. Perhaps static array specialisations are in order then; assuming current implementations can't be modified to suit. > > So, you think that copying a static array is a good idea? Because that's what on overload for a static array would do. And all that overload could do would be to slice the static array and pass it to the normal overload (because static arrays are _not_ ranges and _cannot_ be, because you can't pop any of their elements off), which would lead to the slice being completely invalid once the function returned, meaning that the result would be completely unsafe and invalid. So no, that wouldn't work. I do not think it is a good idea, no, but that was the "clearest" solution... second to that proposed by Timon. map!(c => c[])(cs[]).join(","); But if what you say is unchanging, then there is no point taking it further. Maybe putting something in the documentation/compiler warning so that the error message that is given is not so confusing to those coming from other languages could help. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 30, 2012 [Issue 8910] Static arrays, dynamic arrays and std.array.join | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Cousens | http://d.puremagic.com/issues/show_bug.cgi?id=8910 --- Comment #12 from Daniel Cousens <daniel350@bigpond.com> 2012-10-30 14:06:48 PDT --- Sigh, ignore comment 10... (or delete it, and this) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 30, 2012 [Issue 8910] Static arrays, dynamic arrays and std.array.join | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Cousens | http://d.puremagic.com/issues/show_bug.cgi?id=8910 --- Comment #13 from timon.gehr@gmx.ch 2012-10-30 14:12:53 PDT --- (In reply to comment #9) > > Frankly thats a terrible alternative. Perhaps static array specialisations are in order then; assuming current implementations can't be modified to suit. > > So, you think that copying a static array is a good idea? Because that's what on overload for a static array would do. ... auto rangeFunction(T)(ref T range) if(isStaticArray!T && ...){ return rangeFunction(range[]); } I do not think implicitly slicing static arrays for all range-based functions is really worth the trouble. It would silence all those fruitless discussions though. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 30, 2012 [Issue 8910] Static arrays, dynamic arrays and std.array.join | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Cousens | http://d.puremagic.com/issues/show_bug.cgi?id=8910 --- Comment #14 from timon.gehr@gmx.ch 2012-10-30 14:13:48 PDT --- (In reply to comment #11) > ... > map!(c => c[])(cs[]).join(","); > ... This is not valid. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 30, 2012 [Issue 8910] Static arrays, dynamic arrays and std.array.join | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Cousens | http://d.puremagic.com/issues/show_bug.cgi?id=8910 --- Comment #15 from Daniel Cousens <daniel350@bigpond.com> 2012-10-30 14:17:44 PDT --- (In reply to comment #14) > (In reply to comment #11) > > ... > > map!(c => c[])(cs[]).join(","); > > ... > > This is not valid. Huh. So it isn't, it compiles however, just garbage output. What *is* it doing differently? Also, thanks for bearing with me on this Jonathan M Davis, you're explanation has been a great helping in understanding the problem. :) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 30, 2012 [Issue 8910] Static arrays, dynamic arrays and std.array.join | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Cousens | http://d.puremagic.com/issues/show_bug.cgi?id=8910 --- Comment #16 from bearophile_hugs@eml.cc 2012-10-30 14:20:00 PDT --- (In reply to comment #9) > So, you think that copying a static array is a good idea? Because that's what on overload for a static array would do. And all that overload could do would be to slice the static array and pass it to the normal overload (because static arrays are _not_ ranges and _cannot_ be, because you can't pop any of their elements off), which would lead to the slice being completely invalid once the function returned, meaning that the result would be completely unsafe and invalid. So no, that wouldn't work. This bug report is about a join() that works with fixed-size matrix. join() is supposed to allocate a new array as large as the sum of the rows plus the optional separators. And if this join function is well written (taking fixed sized array by reference and not using the dynamic-array function badly as you say), the result is correct and the requested computation is done efficiently, it's more efficient than the case with dynamic arrays, because there is less indirection and being all the rows of the same length there is no need to read and use every length of each row as in the dynamic array case, because it's surely rectangular. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 30, 2012 [Issue 8910] Static arrays, dynamic arrays and std.array.join | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Cousens | http://d.puremagic.com/issues/show_bug.cgi?id=8910 --- Comment #17 from Daniel Cousens <daniel350@bigpond.com> 2012-10-30 14:21:40 PDT --- (In reply to comment #15) > (In reply to comment #14) > > (In reply to comment #11) > > > ... > > > map!(c => c[])(cs[]).join(","); > > > ... > > > > This is not valid. > > Huh. So it isn't, it compiles however, just garbage output. What *is* it doing differently? > > Also, thanks for bearing with me on this Jonathan M Davis, you're explanation has been a great helping in understanding the problem. :) Right, so it is passing in a random static array of char[5] into the function, which contains garbage. By doing `char[] j = map!((char[] c) => c)(cs[]).join(",");`, you are forcing the template input to be a char[], which has implicit casting, and therefore returns a slice (note, AFAIK the second slice wasn't necessary on c). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 30, 2012 [Issue 8910] Static arrays, dynamic arrays and std.array.join | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Cousens | http://d.puremagic.com/issues/show_bug.cgi?id=8910 --- Comment #18 from timon.gehr@gmx.ch 2012-10-30 14:24:25 PDT --- (In reply to comment #15) > (In reply to comment #14) > > (In reply to comment #11) > > > ... > > > map!(c => c[])(cs[]).join(","); > > > ... > > > > This is not valid. > > Huh. So it isn't, it compiles however, just garbage output. > What *is* it doing differently? > ... This copies the static arrays to a function-local parameter, slices them and returns those slices. i.e. it escapes stack addresses. It should be a compile error. Mine implicitly slices the original static arrays before they are passed in and returns those slices. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 30, 2012 [Issue 8910] Static arrays, dynamic arrays and std.array.join | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Cousens | http://d.puremagic.com/issues/show_bug.cgi?id=8910 --- Comment #19 from Jonathan M Davis <jmdavisProg@gmx.com> 2012-10-30 15:59:40 PDT --- Slicing static arrays is unsafe (and really should be considered to be @system - issue# 8838), so it really shouldn't be happening silently. If it were up to me, static arrays would _never_ be implicitly sliced precisely because of how dangerous it is. It's useful and should be permitted, but it should be explicit. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation