April 16, 2012
On Wed, 2012-04-11 at 18:32 +0200, Jakob Ovrum wrote:
[...]
> Ranges are iterated in-place. You can't mutate a const range, hence you cannot advance it by one (`popFront`), which is required by the lowering of foreach using the range interface.
[...]

I think I am still trying to recover from the shock of this; it is very likely to turn anyone interested in any form of declarative expression away from D. Also the internal activity is being exposed at the API level.  Not to mention the history of iteration being one of working with mutable object on immutable structures.

Trying to create the smallest possible example:

	auto r = iota ( 0 , 10 ) ;
	writeln ( map ! ( i => i * i ) ( r ) ) ;

works fine. Let us try:

	const r = iota ( 0 , 10 ) ;
	writeln ( map ! ( i => i * i ) ( r ) ) ;

works fine. Great. Now

	auto r = iota ( 0 , 10 ) ;
	writeln ( reduce ! ( ( a, b ) => a + b ) ( 10 , r ) ) ;

works fine. Let's try:

	const r = iota ( 0 , 10 ) ;
	writeln ( reduce ! ( ( a, b ) => a + b ) ( 10 , r ) ) ;

Oh dear:

/home/users/russel/lib.Linux.x86_64/DMD2/bin64/../../src/phobos/std/algorithm.d(725): Error: function std.range.iota!(int,int).iota.Result.popFront () is not callable using argument types ()
/home/users/russel/lib.Linux.x86_64/DMD2/bin64/../../src/phobos/std/algorithm.d(725): Error: function std.range.iota!(int,int).iota.Result.front () is not callable using argument types ()
example.d(7): Error: template instance example.main.reduce!(__lambda3).reduce!(int,const(Result)) error instantiating

Not only is the error message incomprehensible to someone who doesn't know the details of the internal workings (OK not a killer blow), but the very inconsistency of behaviour between map and reduce is a violation of the Principle of Least Surprise, and seems like a killer blow.
-- 
Russel. ============================================================================= Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder@ekiga.net 41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@winder.org.uk London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder


April 16, 2012
On 04/16/2012 01:20 PM, Russel Winder wrote:
> On Wed, 2012-04-11 at 18:32 +0200, Jakob Ovrum wrote:
> [...]
>> Ranges are iterated in-place. You can't mutate a const range,
>> hence you cannot advance it by one (`popFront`), which is
>> required by the lowering of foreach using the range interface.
> [...]
>
> I think I am still trying to recover from the shock of this; it is very
> likely to turn anyone interested in any form of declarative expression
> away from D. Also the internal activity is being exposed at the API
> level.  Not to mention the history of iteration being one of working
> with mutable object on immutable structures.
>
> Trying to create the smallest possible example:
>
> 	auto r = iota ( 0 , 10 ) ;
> 	writeln ( map ! ( i =>  i * i ) ( r ) ) ;
>
> works fine. Let us try:
>
> 	const r = iota ( 0 , 10 ) ;
> 	writeln ( map ! ( i =>  i * i ) ( r ) ) ;
>
> works fine. Great. Now
>
> 	auto r = iota ( 0 , 10 ) ;
> 	writeln ( reduce ! ( ( a, b ) =>  a + b ) ( 10 , r ) ) ;
>
> works fine. Let's try:
>
> 	const r = iota ( 0 , 10 ) ;
> 	writeln ( reduce ! ( ( a, b ) =>  a + b ) ( 10 , r ) ) ;
>
> Oh dear:
>
> /home/users/russel/lib.Linux.x86_64/DMD2/bin64/../../src/phobos/std/algorithm.d(725): Error: function std.range.iota!(int,int).iota.Result.popFront () is not callable using argument types ()
> /home/users/russel/lib.Linux.x86_64/DMD2/bin64/../../src/phobos/std/algorithm.d(725): Error: function std.range.iota!(int,int).iota.Result.front () is not callable using argument types ()
> example.d(7): Error: template instance example.main.reduce!(__lambda3).reduce!(int,const(Result)) error instantiating
>
> Not only is the error message incomprehensible to someone who doesn't
> know the details of the internal workings (OK not a killer blow), but
> the very inconsistency of behaviour between map and reduce is a
> violation of the Principle of Least Surprise, and seems like a killer
> blow.

Have you filed a bug report against Phobos for this?
April 16, 2012
On Mon, 2012-04-16 at 14:58 +0200, Timon Gehr wrote:
[...]
> Have you filed a bug report against Phobos for this?

Not as yet, after lunch 'twill be done.

-- 
Russel. ============================================================================= Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder@ekiga.net 41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@winder.org.uk London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder


1 2
Next ›   Last »