[Issue 9437] unwanted behavior from phobos range

2017-08-24 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=9437

RazvanN  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 CC||razvan.nitu1...@gmail.com
 Resolution|--- |INVALID

--- Comment #6 from RazvanN  ---
Closing as invalid.

--


[Issue 9437] unwanted behavior from phobos range

2013-02-01 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=9437



--- Comment #5 from monarchdo...@gmail.com 2013-02-01 07:36:26 PST ---
(In reply to comment #4)
> i do not talk to modify a range while is in a loop but access to const method
> should be possible.
>  name() const { ... }
> 
> what is silently ?
> 
> 
> R r = R( "Hello D users" );
> foreach( l; r )
> writeln( l, ", ", r.front() );
> 
> you have 2 variable r and are not the same for me is dangerous. I know now 
> what
> happen.
> But when you look this code it seem ok but is not.

But that's the point, in that code, both "r" ARE the same variable. r is r. It
is the *iteration* that is done on an un-named copy.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 9437] unwanted behavior from phobos range

2013-02-01 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=9437



--- Comment #4 from bioinfornatics  2013-02-01 
07:16:24 PST ---
i do not talk to modify a range while is in a loop but access to const method
should be possible.
 name() const { ... }

what is silently ?


R r = R( "Hello D users" );
foreach( l; r )
writeln( l, ", ", r.front() );

you have 2 variable r and are not the same for me is dangerous. I know now what
happen.
But when you look this code it seem ok but is not.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 9437] unwanted behavior from phobos range

2013-02-01 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=9437



--- Comment #3 from monarchdo...@gmail.com 2013-02-01 06:31:01 PST ---
(In reply to comment #2)
> Ok, but silently doing this that is really bad and a is really a thing in D
> where could create many bug

But silently doing what? If the range provides random access, then which
behavior would you expect?

//
int arr[] = [1, 2, 3]

foreach ( a ; arr)
writeln(arr.front); //So this print 1, 2, 3?

assert(arr.length == 3); //But this should pass?
//

The expected behavior of foreach is *only* to iterate on each element of the
range, but it is also expected to *not* modify the range.

It is modifying the range that would provide surprising results.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 9437] unwanted behavior from phobos range

2013-02-01 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=9437



--- Comment #2 from bioinfornatics  2013-02-01 
06:25:56 PST ---
Ok, but silently doing this that is really bad and a is really a thing in D
where could create many bug

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 9437] unwanted behavior from phobos range

2013-02-01 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=9437


monarchdo...@gmail.com changed:

   What|Removed |Added

 CC||monarchdo...@gmail.com


--- Comment #1 from monarchdo...@gmail.com 2013-02-01 06:00:04 PST ---
This works as intended, and is the documented behavior of foreach.

foreach is supposed to be used on the elements only. You cannot add, remove, or
interface with the range in general during a foreach. If you need a more
specific behavior, just use a for:

void main( string[] args ){
R r = R( "Hello D users" );
for( ; !r.empty ; r.popFront() )
{
auto l = r.front;
writeln( l, ", ", r.front() );
}
}

Please see the thread in regards to the mm file thing.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---