Re: Passing a reference to a returned reference

2018-07-06 Thread Michael via Digitalmars-d-learn
On Friday, 6 July 2018 at 16:24:03 UTC, Timoses wrote: On Friday, 6 July 2018 at 15:51:34 UTC, Michael wrote: [...] While writing I realized that the following is even the case without the 'ref' parameter: The caller of the setter will still be able to change the content of your private data

Re: Passing a reference to a returned reference

2018-07-06 Thread Timoses via Digitalmars-d-learn
On Friday, 6 July 2018 at 15:51:34 UTC, Michael wrote: Also, yes, I am using the setter method to play around with the precision of the double values, and do some normalising. While writing I realized that the following is even the case without the 'ref' parameter: The caller of the setter will

Re: Passing a reference to a returned reference

2018-07-06 Thread Michael via Digitalmars-d-learn
On Friday, 6 July 2018 at 15:57:27 UTC, Timoses wrote: On Friday, 6 July 2018 at 15:33:18 UTC, Michael wrote: This is definitely to do with my use of the setter syntax, which maybe I am misunderstanding? Because if I change it to a normal function call like so:

Re: Passing a reference to a returned reference

2018-07-06 Thread Timoses via Digitalmars-d-learn
On Friday, 6 July 2018 at 15:33:18 UTC, Michael wrote: This is definitely to do with my use of the setter syntax, which maybe I am misunderstanding? Because if I change it to a normal function call like so: a.beliefs(Operator.create()); then it complains if I use ref, and doesn't complain

Re: Passing a reference to a returned reference

2018-07-06 Thread Michael via Digitalmars-d-learn
On Friday, 6 July 2018 at 15:37:25 UTC, Timoses wrote: On Friday, 6 July 2018 at 15:14:01 UTC, Michael wrote: class Agent { private { double[int] mDict; } // Setter: copy void beliefs(ref double[int] dict) { import std.stdio : writeln;

Re: Passing a reference to a returned reference

2018-07-06 Thread Timoses via Digitalmars-d-learn
On Friday, 6 July 2018 at 15:14:01 UTC, Michael wrote: class Agent { private { double[int] mDict; } // Setter: copy void beliefs(ref double[int] dict) { import std.stdio : writeln; writeln("Setter function."); this.mDict = dict; }

Re: Passing a reference to a returned reference

2018-07-06 Thread Michael via Digitalmars-d-learn
On Friday, 6 July 2018 at 15:14:01 UTC, Michael wrote: On Friday, 6 July 2018 at 14:50:39 UTC, Ali Çehreli wrote: [...] I'm just trying to do that now. Here is what I have in terms of code: [...] This is definitely to do with my use of the setter syntax, which maybe I am

Re: Passing a reference to a returned reference

2018-07-06 Thread Michael via Digitalmars-d-learn
On Friday, 6 July 2018 at 14:50:39 UTC, Ali Çehreli wrote: On 07/06/2018 07:36 AM, Michael wrote: > but not in > my case, if this is a weird edge-case with setter member functions? This is all very interesting but I'm dying to see the code. :) Can you change Timoses's code to demonstrate your

Re: Passing a reference to a returned reference

2018-07-06 Thread Ali Çehreli via Digitalmars-d-learn
On 07/06/2018 07:36 AM, Michael wrote: > but not in > my case, if this is a weird edge-case with setter member functions? This is all very interesting but I'm dying to see the code. :) Can you change Timoses's code to demonstrate your case? Ali

Re: Passing a reference to a returned reference

2018-07-06 Thread Michael via Digitalmars-d-learn
On Friday, 6 July 2018 at 14:11:42 UTC, Timoses wrote: This works for me: auto create() { string[int] dict; dict[2] = "hello"; return dict; } void modifyNoRef(string[int] m) { writeln("Address not ref: ", ); m[0] = "modified";

Re: Passing a reference to a returned reference

2018-07-06 Thread Michael via Digitalmars-d-learn
On Friday, 6 July 2018 at 14:11:42 UTC, Timoses wrote: On Friday, 6 July 2018 at 13:13:43 UTC, Michael wrote: static auto ref consensus( ... ) `auto ref` infers the return type from the return statement [1]. So it's not necessarily returning a ref type. However, I don't think this matters

Re: Passing a reference to a returned reference

2018-07-06 Thread Timoses via Digitalmars-d-learn
On Friday, 6 July 2018 at 13:13:43 UTC, Michael wrote: static auto ref consensus( ... ) `auto ref` infers the return type from the return statement [1]. So it's not necessarily returning a ref type. However, I don't think this matters if the only concern you have is that the setter

Passing a reference to a returned reference

2018-07-06 Thread Michael via Digitalmars-d-learn
Hello, I'm a little confused about what is actually happening when I try to pass a reference, returned by a method that produces the object (associative array), to a setter method which expects a reference. What seems to be happening is that it simply does nothing, as if the setter method is