Thread overview | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
December 10, 2011 Why D const is annoying | ||||
---|---|---|---|---|
| ||||
I just thought I'd give D another try, after having given up on it for a while. Lo and behold... the same old kind of problem from a year ago is still here. :( Simple stuff like this: import std.algorithm; void main() { const arr = [1, 2, 3]; reduce!"a*b"(arr); // You'd think it'd work... } Results in ridiculously annoying errors like: // algorithm.d(728): Error: can only initialize const member _field_field_0 inside constructor I **HIGHLY** suggest that priority be given to simple problems like these, instead of OMG-so-cool-libraries. It really doesn't matter if there is an uber-awesome collections/CURL/whatever library out there, when problems like these exist. If a 2-line piece of code needs a workaround, then (IMO) people simply won't care about anything else that's more complicated. I'll post more as I find them. (I'd found plenty a few months ago, now I just need to find them again.) Too lazy/busy studying to post as a bug. And it feels a bit better when I add the complaint. :P (Sorry for being so critical but at least I tried to make it constructive...) |
December 10, 2011 Re: Why D const is annoying | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mehrdad | Moar coming... hey look, it's ANOTHER const-ness issue! :( import std.algorithm; struct Matrix { size_t[] _lengths; @property inout(size_t)[] lengths() inout { return _lengths; } @property size_t length() inout { return reduce!q{a*b}(lengths); } } // Error: template std.algorithm.reduce!("a*b").reduce(Args...) if (Args.length > 0 && Args.length <= 2 && isIterable!(Args[__dollar - 1])) does not match any function template declaration // Error: template std.algorithm.reduce!("a*b").reduce(Args...) if (Args.length > 0 && Args.length <= 2 && isIterable!(Args[__dollar - 1])) cannot deduce template function from argument types !()(inout(uint[2u])) |
December 10, 2011 Re: Why D const is annoying | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mehrdad | On 12/10/2011 10:43 AM, Mehrdad wrote: > Moar coming... hey look, it's ANOTHER const-ness issue! :( > > import std.algorithm; > struct Matrix > { > size_t[] _lengths; > @property inout(size_t)[] lengths() inout { return _lengths; } > @property size_t length() inout { return reduce!q{a*b}(lengths); } > } > > // Error: template std.algorithm.reduce!("a*b").reduce(Args...) if > (Args.length > 0 && Args.length <= 2 && isIterable!(Args[__dollar - 1])) > does not match any function template declaration > // Error: template std.algorithm.reduce!("a*b").reduce(Args...) if > (Args.length > 0 && Args.length <= 2 && isIterable!(Args[__dollar - 1])) > cannot deduce template function from argument types !()(inout(uint[2u])) http://d.puremagic.com/issues/show_bug.cgi?id=6809 |
December 10, 2011 Re: Why D const is annoying | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mehrdad | On 12/10/2011 10:37 AM, Mehrdad wrote: > I just thought I'd give D another try, after having given up on it for a > while. > > Lo and behold... the same old kind of problem from a year ago is still > here. :( > > Simple stuff like this: > > import std.algorithm; > void main() { > const arr = [1, 2, 3]; > reduce!"a*b"(arr); // You'd think it'd work... > } > > Results in ridiculously annoying errors like: > // algorithm.d(728): Error: can only initialize const member > _field_field_0 inside constructor > > I **HIGHLY** suggest that priority be given to simple problems like > these, instead of OMG-so-cool-libraries. It is a *library bug*. Just have a look at the source code. > It really doesn't matter if > there is an uber-awesome collections/CURL/whatever library out there, > when problems like these exist. If a 2-line piece of code needs a > workaround, then (IMO) people simply won't care about anything else > that's more complicated. > > I'll post more as I find them. (I'd found plenty a few months ago, now I > just need to find them again.) > Too lazy/busy studying to post as a bug. And it feels a bit better when > I add the complaint. :P > > (Sorry for being so critical but at least I tried to make it > constructive...) Just slice the const array to get a range. The specialization for ranges does not have the bug. import std.algorithm; void main() { const arr = [1, 2, 3]; reduce!"a*b"(arr[]); // It works. } |
December 10, 2011 Re: Why D const is annoying | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mehrdad | ... and another... struct S(T, int N) { public auto opBinary(string op)(in S!(T, N) other) const { return this; } } void main() { S!(int, 1) m; m = m * m; } Error: 'm' is not of arithmetic type, it is a Matrix!(int,1) Error: 'm' is not of arithmetic type, it is a Matrix!(int,1) |
December 10, 2011 Re: Why D const is annoying | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mehrdad | On Sat, 10 Dec 2011 12:18:31 +0200, Mehrdad <wfunction@hotmail.com> wrote:
> ... and another...
>
> struct S(T, int N)
> { public auto opBinary(string op)(in S!(T, N) other) const { return this; } }
> void main() { S!(int, 1) m; m = m * m; }
>
> Error: 'm' is not of arithmetic type, it is a Matrix!(int,1)
> Error: 'm' is not of arithmetic type, it is a Matrix!(int,1)
Oh fantastic, so you are writing the first bug-free software of our time?
|
December 10, 2011 Re: Why D const is annoying | ||||
---|---|---|---|---|
| ||||
Posted in reply to so | On 12/10/2011 2:28 AM, so wrote:
> On Sat, 10 Dec 2011 12:18:31 +0200, Mehrdad <wfunction@hotmail.com> wrote:
>
>> ... and another...
>>
>> struct S(T, int N)
>> { public auto opBinary(string op)(in S!(T, N) other) const { return this; } }
>> void main() { S!(int, 1) m; m = m * m; }
>>
>> Error: 'm' is not of arithmetic type, it is a Matrix!(int,1)
>> Error: 'm' is not of arithmetic type, it is a Matrix!(int,1)
>
> Oh fantastic, so you are writing the first bug-free software of our time?
Nope, sorry. :(
I'm listing a bunch of bugs I've found. And yes, I'm [semi-]complaining about them in the process.
|
December 10, 2011 Re: Why D const is annoying | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mehrdad | ... and another... struct Matrix(T, size_t N = 1) { public auto mul(Matrix!(T, N) other) const { return this; } } void main() { Matrix!(int, 2) m; m.mul(m); } annoy.d(7): Error: function annoy.Matrix!(int,2).Matrix.mul (Matrix!(int,N) other) const is not callable using argument types (Matrix!(int,2)) annoy.d(7): Error: cannot implicitly convert expression (m) of type Matrix!(int,2) to Matrix!(int,N) |
December 10, 2011 Re: Why D const is annoying | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mehrdad | ... and another... struct S(L...) { enum N = L[0]; S!(N) me() { return this; } } alias S!(1) S2; annoy.d(3): Error: template instance annoy.S!(N) recursive expansion |
December 10, 2011 Re: Why D const is annoying | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | Timon Gehr:
> Just slice the const array to get a range. The specialization for ranges does not have the bug.
>
> import std.algorithm;
> void main() {
> const arr = [1, 2, 3];
> reduce!"a*b"(arr[]); // It works.
> }
Wasn't arr a range already?
Bye,
bearophile
|
Copyright © 1999-2021 by the D Language Foundation