Re: foreach ref very broken: fails to call front(val)

2012-07-16 Thread monarch_dodra
andralex wrote: We need to improve ranges instead of using opApply for such trivial iteration patterns. Apologies that the thread didn't make this clear. Will close this now - sorry. Thanks for taking the time to process my pull request. I'd argue that we could keep the opApply fix until

Re: foreach ref very broken: fails to call front(val)

2012-07-16 Thread Mehrdad
On Tuesday, 10 July 2012 at 22:22:12 UTC, Timon Gehr wrote: 'scope ref' ? http://d.puremagic.com/issues/show_bug.cgi?id=8121

Re: foreach ref very broken: fails to call front(val)

2012-07-11 Thread monarch_dodra
Giving Array an opApply operator fixes both problems: 1) It allows modifying the elements when accessed with ref. 2) It allows writing ++a even though ++front isn't supported. I implemented this and made a pull request: https://github.com/D-Programming-Language/phobos/pull/683 I implemented

Re: foreach ref very broken: fails to call front(val)

2012-07-10 Thread monarch_dodra
On Monday, 9 July 2012 at 09:24:29 UTC, monarch_dodra wrote: ... Forgive me for insisting, but at this point, I'm just trying to figure out if I am being stupid and misunderstood how D works. Could someone please just tell me if what I'm seeing is expected?

Re: foreach ref very broken: fails to call front(val)

2012-07-10 Thread Daniel Murphy
monarch_dodra monarch_do...@gmail.com wrote in message news:fbithbggnynmazrxk...@forum.dlang.org... On Monday, 9 July 2012 at 09:24:29 UTC, monarch_dodra wrote: ... Forgive me for insisting, but at this point, I'm just trying to figure out if I am being stupid and misunderstood how D works.

Re: foreach ref very broken: fails to call front(val)

2012-07-10 Thread monarch_dodra
On Monday, 9 July 2012 at 09:24:29 UTC, monarch_dodra wrote: ... Forgive me for insisting, but at this point, I'm just trying to figure out if I am being stupid and misunderstood how D works. Could someone please tell me if what I'm seeing is expected?

Re: foreach ref very broken: fails to call front(val)

2012-07-10 Thread kenji hara
There are two problems: 1. std.container.Array.(front, back, opIndex, ...) doesn't return its elements by ref. 2. std.algorithm.map doesn't consider original range's ref-ness. Bye. Kenji Hara 2012/7/2 monarch_dodra monarch_do...@gmail.com: I think this is a pretty serious bug: when one

Re: foreach ref very broken: fails to call front(val)

2012-07-10 Thread Ali Çehreli
On 07/09/2012 02:24 AM, monarch_dodra wrote: On Monday, 2 July 2012 at 12:44:59 UTC, monarch_dodra wrote: ... I opened this thread a week ago, and got little no feed back. Please also consider the D.learn newsgroup. Some people are more responsive over there. :) (And you may have already

Re: foreach ref very broken: fails to call front(val)

2012-07-10 Thread Ali Çehreli
On 07/10/2012 12:21 AM, kenji hara wrote: There are two problems: 1. std.container.Array.(front, back, opIndex, ...) doesn't return its elements by ref. It's not that obvious to me. The following picture should supposedly provide references to elements: The latter of the following pair of

Re: foreach ref very broken: fails to call front(val)

2012-07-10 Thread kenji hara
Posted a pull request: https://github.com/D-Programming-Language/phobos/pull/678 With the patch, following code works as expected. import std.container; import std.stdio; import std.algorithm; void main() { Array!int arr; arr.length = 3; foreach(ref a; arr) // requre 'ref'

Re: foreach ref very broken: fails to call front(val)

2012-07-10 Thread Andrei Alexandrescu
On 7/10/12 4:29 AM, kenji hara wrote: Posted a pull request: https://github.com/D-Programming-Language/phobos/pull/678 Hmm, that has a couple of issues. First, map that modifies things in place is a bug more often than a feature given that the caller of map may use front() an arbitrary

Re: foreach ref very broken: fails to call front(val)

2012-07-10 Thread kenji hara
2012/7/10 Andrei Alexandrescu seewebsiteforem...@erdani.org: On 7/10/12 4:29 AM, kenji hara wrote: Posted a pull request: https://github.com/D-Programming-Language/phobos/pull/678 Hmm, that has a couple of issues. First, map that modifies things in place is a bug more often than a feature

Re: foreach ref very broken: fails to call front(val)

2012-07-10 Thread Andrei Alexandrescu
On 7/10/12 10:32 AM, kenji hara wrote: OK. I know the past discussion about 'sealed container' so I can agree with your argument. Then I'll close the pull request. Sounds good for now but let's keep in mind the possibility of restricting ref returns. At that point we can open up ref returns

Re: foreach ref very broken: fails to call front(val)

2012-07-10 Thread Timon Gehr
On 07/10/2012 05:01 PM, Andrei Alexandrescu wrote: On 7/10/12 10:32 AM, kenji hara wrote: OK. I know the past discussion about 'sealed container' so I can agree with your argument. Then I'll close the pull request. Sounds good for now but let's keep in mind the possibility of restricting ref

Re: foreach ref very broken: fails to call front(val)

2012-07-10 Thread Andrei Alexandrescu
On 7/10/12 11:03 AM, Timon Gehr wrote: On 07/10/2012 05:01 PM, Andrei Alexandrescu wrote: On 7/10/12 10:32 AM, kenji hara wrote: OK. I know the past discussion about 'sealed container' so I can agree with your argument. Then I'll close the pull request. Sounds good for now but let's keep in

Re: foreach ref very broken: fails to call front(val)

2012-07-10 Thread monarch_dodra
On Tuesday, 10 July 2012 at 14:19:04 UTC, Andrei Alexandrescu wrote: ... Second, the return by value from Array is intentional and has to do with sealing. Array is intended to never escape the addresses of its elements. That way, the collection is sealed in the sense there can never be

Re: foreach ref very broken: fails to call front(val)

2012-07-10 Thread Jonathan M Davis
On Tuesday, July 10, 2012 23:25:41 monarch_dodra wrote: On Tuesday, 10 July 2012 at 14:19:04 UTC, Andrei Alexandrescu wrote: ... Second, the return by value from Array is intentional and has to do with sealing. Array is intended to never escape the addresses of its elements. That

Re: foreach ref very broken: fails to call front(val)

2012-07-10 Thread Timon Gehr
On 07/10/2012 11:51 PM, Jonathan M Davis wrote: On Tuesday, July 10, 2012 23:25:41 monarch_dodra wrote: ... And more generally, how would code like this _ever_ work? Array!int arr foreach(ref a; arr) a += 5; Since there is no mechanism to pass the op to front? I believe that according to

Re: foreach ref very broken: fails to call front(val)

2012-07-10 Thread Timon Gehr
On 07/10/2012 05:07 PM, Andrei Alexandrescu wrote: On 7/10/12 11:03 AM, Timon Gehr wrote: On 07/10/2012 05:01 PM, Andrei Alexandrescu wrote: On 7/10/12 10:32 AM, kenji hara wrote: OK. I know the past discussion about 'sealed container' so I can agree with your argument. Then I'll close the

Re: foreach ref very broken: fails to call front(val)

2012-07-10 Thread Jonathan M Davis
On Wednesday, July 11, 2012 00:15:34 Timon Gehr wrote: On 07/10/2012 11:51 PM, Jonathan M Davis wrote: On Tuesday, July 10, 2012 23:25:41 monarch_dodra wrote: ... And more generally, how would code like this _ever_ work? Array!int arr foreach(ref a; arr) a += 5; Since there is

Re: foreach ref very broken: fails to call front(val)

2012-07-09 Thread monarch_dodra
On Monday, 2 July 2012 at 12:44:59 UTC, monarch_dodra wrote: ... I opened this thread a week ago, and got little no feed back. I've realized since: 1) map was a bad example, since it actually returns a new range (does not modify the underlying values), so the output was normal 2) I pasted

Re: foreach ref very broken: fails to call front(val)

2012-07-02 Thread bearophile
On Monday, 2 July 2012 at 12:44:59 UTC, monarch_dodra wrote: I think this is a pretty serious bug: when one writes: foreach(ref a, range), the underlying (ref'd) object will ONLY get modified if the range object provides a ref T front() method. Somethig related, zip(a,b) allows to sort the