Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
August 06, 2012 [phobos] bug in map | ||||
---|---|---|---|---|
| ||||
Consider:
auto s = "some string";
static assert(!hasLength(typeof(s));
auto m = map!(a => a)(s);
static assert(!hasLength(typeof(s));
Both asserts should pass: string famously has a length that's actually not the length of the range. Then mapping something on top of the string should also have no meaningful length. Alas, it does, because of the following code in std.algorithm:
static if (hasLength!R || isSomeString!R)
{
@property auto length()
{
return _input.length;
}
alias length opDollar;
}
The code used to introduce length only if if (hasLength!R).
It seems Kenji introduced this change. What was its purpose, and can we undo it? This breaks the entire web of assumptions that hasLength builds.
Thanks,
Andrei
_______________________________________________
phobos mailing list
phobos@puremagic.com
http://lists.puremagic.com/mailman/listinfo/phobos
|
August 06, 2012 Re: [phobos] bug in map | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On 6 aug 2012, at 20:55, Andrei Alexandrescu wrote: > Consider: > > auto s = "some string"; > static assert(!hasLength(typeof(s)); > auto m = map!(a => a)(s); > static assert(!hasLength(typeof(s)); Do you mean: static assert(!hasLength(typeof(m))); For the second assert? -- /Jacob Carlborg _______________________________________________ phobos mailing list phobos@puremagic.com http://lists.puremagic.com/mailman/listinfo/phobos |
August 06, 2012 Re: [phobos] bug in map | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On 8/6/12 3:11 PM, Jacob Carlborg wrote: > > On 6 aug 2012, at 20:55, Andrei Alexandrescu wrote: > >> Consider: >> >> auto s = "some string"; >> static assert(!hasLength(typeof(s)); >> auto m = map!(a => a)(s); >> static assert(!hasLength(typeof(s)); > > > Do you mean: > > static assert(!hasLength(typeof(m))); > > For the second assert? Yes, apologies. Essentially mapping a function over characters in a string should not automagically define a length property. Andrei _______________________________________________ phobos mailing list phobos@puremagic.com http://lists.puremagic.com/mailman/listinfo/phobos |
August 06, 2012 Re: [phobos] bug in map | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Monday, August 06, 2012 14:55:56 Andrei Alexandrescu wrote: > It seems Kenji introduced this change. What was its purpose, and can we undo it? This breaks the entire web of assumptions that hasLength builds. Then create a bug report and mark it as a regression. I don't think that there's any real question that it's wrong. - Jonathan M Davis _______________________________________________ phobos mailing list phobos@puremagic.com http://lists.puremagic.com/mailman/listinfo/phobos |
August 07, 2012 Re: [phobos] bug in map | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | It seems to me that is an old bug. https://github.com/D-Programming-Language/phobos/commit/3e6679b2973069ba9191da16fd74d8b8b80865eb#L1L437 Regards. Kenji Hara 2012/8/7 Andrei Alexandrescu <andrei@erdani.com>: > Consider: > > auto s = "some string"; > static assert(!hasLength(typeof(s)); > auto m = map!(a => a)(s); > static assert(!hasLength(typeof(s)); > > Both asserts should pass: string famously has a length that's actually not the length of the range. Then mapping something on top of the string should also have no meaningful length. Alas, it does, because of the following code in std.algorithm: > > static if (hasLength!R || isSomeString!R) > { > @property auto length() > { > return _input.length; > } > alias length opDollar; > } > > The code used to introduce length only if if (hasLength!R). > > It seems Kenji introduced this change. What was its purpose, and can we undo it? This breaks the entire web of assumptions that hasLength builds. > > > Thanks, > > Andrei > _______________________________________________ > phobos mailing list > phobos@puremagic.com > http://lists.puremagic.com/mailman/listinfo/phobos _______________________________________________ phobos mailing list phobos@puremagic.com http://lists.puremagic.com/mailman/listinfo/phobos |
August 17, 2012 Re: [phobos] bug in map | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On 06-Aug-12 22:55, Andrei Alexandrescu wrote: > Consider: > > auto s = "some string"; > static assert(!hasLength(typeof(s)); > auto m = map!(a => a)(s); > static assert(!hasLength(typeof(s)); > > Both asserts should pass: string famously has a length that's actually not the length of the range. Then mapping something on top of the string should also have no meaningful length. Alas, it does, because of the following code in std.algorithm: > > static if (hasLength!R || isSomeString!R) > { > @property auto length() > { > return _input.length; > } > alias length opDollar; > } > > The code used to introduce length only if if (hasLength!R). > > It seems Kenji introduced this change. What was its purpose, and can we undo it? This breaks the entire web of It bugs me - the indecision on this matter. No Kenji didn't introduce it. The guilty commit (that could be reverted on it's own): SHA-1: d0457fe82a5f140218d8a9700eb7c26a236d4abe * This test is actually needed Adds "isSomeString" to map's "length" test. Author: monarchdodra Contains one line diff that goes as follows: -static if (hasLength!R) +static if (hasLength!R || isSomeString!R) P.S. I do not suggest to gill our new contributors but to pay more attention during the review of pulls. -- Olshansky Dmitry _______________________________________________ phobos mailing list phobos@puremagic.com http://lists.puremagic.com/mailman/listinfo/phobos |
Copyright © 1999-2021 by the D Language Foundation