Arrays passed by almost reference?

2009-11-05 Thread Ali Cehreli
I haven't started reading Andrei's chapter on arrays yet. I hope I won't find out that the following behavior is expected. :) import std.cstream; void modify(int[] a) { a[0] = 1; a ~= 2; dout.writefln("During: ", a); } void main() { int[] a = [ 0 ]; dout.writefln("Before:

Re: Arrays passed by almost reference?

2009-11-05 Thread dsimcha
== Quote from Ali Cehreli (acehr...@yahoo.com)'s article > I haven't started reading Andrei's chapter on arrays yet. I hope I won't find out that the following behavior is expected. :) > import std.cstream; > void modify(int[] a) > { > a[0] = 1; > a ~= 2; > dout.writefln("During: ", a);

Re: Arrays passed by almost reference?

2009-11-05 Thread Frank Benoit
Ali Cehreli schrieb: > I haven't started reading Andrei's chapter on arrays yet. I hope I won't find > out that the following behavior is expected. :) > > import std.cstream; > > void modify(int[] a) > { > a[0] = 1; > a ~= 2; > > dout.writefln("During: ", a); > } > > void main() >

Re: Arrays passed by almost reference?

2009-11-05 Thread Travis Boucher
dsimcha wrote: == Quote from Ali Cehreli (acehr...@yahoo.com)'s article I haven't started reading Andrei's chapter on arrays yet. I hope I won't find out that the following behavior is expected. :) import std.cstream; void modify(int[] a) { a[0] = 1; a ~= 2; dout.writefln("During:

Re: Arrays passed by almost reference?

2009-11-05 Thread Nick Sabalausky
"Frank Benoit" wrote in message news:hcvff9$9c...@digitalmars.com... > Ali Cehreli schrieb: >> I haven't started reading Andrei's chapter on arrays yet. I hope I won't >> find out that the following behavior is expected. :) >> >> import std.cstream; >> >> void modify(int[] a) >> { >> a[0] =

Re: Arrays passed by almost reference?

2009-11-05 Thread Andrei Alexandrescu
dsimcha wrote: == Quote from Ali Cehreli (acehr...@yahoo.com)'s article I haven't started reading Andrei's chapter on arrays yet. I hope I won't find out that the following behavior is expected. :) import std.cstream; void modify(int[] a) { a[0] = 1; a ~= 2; dout.writefln("During:

Re: Arrays passed by almost reference?

2009-11-05 Thread Ali Cehreli
Thanks for all the responses. And yes, I know that 'ref' is what works for me here. I am trying to figure out whether I should develop a guideline like "always pass arrays with 'ref', or you may face surprises." I understand it very well now and was able to figure out a way to cause some bugs.

Re: Arrays passed by almost reference?

2009-11-05 Thread Andrei Alexandrescu
Ali Cehreli wrote: Thanks for all the responses. And yes, I know that 'ref' is what works for me here. I am trying to figure out whether I should develop a guideline like "always pass arrays with 'ref', or you may face surprises." I understand it very well now and was able to figure out a way

Re: Arrays passed by almost reference?

2009-11-05 Thread Saaa
Ali Cehreli wrote... This helps me with the meaning of in, out & ref. http://bayimg.com/NaeOgaaCC

Re: Arrays passed by almost reference?

2009-11-05 Thread Leandro Lucarella
Andrei Alexandrescu, el 5 de noviembre a las 16:10 me escribiste: > Ali Cehreli wrote: > >Thanks for all the responses. > > > >And yes, I know that 'ref' is what works for me here. I am trying to figure > >out whether I should develop a guideline like "always pass arrays with > >'ref', or you ma

Re: Arrays passed by almost reference?

2009-11-05 Thread Travis Boucher
Leandro Lucarella wrote: Andrei Alexandrescu, el 5 de noviembre a las 16:10 me escribiste: Ali Cehreli wrote: Thanks for all the responses. And yes, I know that 'ref' is what works for me here. I am trying to figure out whether I should develop a guideline like "always pass arrays with 'ref'

Re: Arrays passed by almost reference?

2009-11-05 Thread Leandro Lucarella
Travis Boucher, el 5 de noviembre a las 20:44 me escribiste: > >>>I don't think that this is easy to explain to a learner; and I think that > >>>is a good indicator that there is a problem with these semantics. > >>The ball is in your court to define better semantics. > > > >Just make arrays a re

Re: Arrays passed by almost reference?

2009-11-05 Thread Travis Boucher
I am not fully against pass-by-ref arrays, I just think in passing by reference all of the time could have some performance implications. OK, make 2 different types then: slices (value types, can't append, they are only a view on other's data) and dynamic arrays (reference type, can append, but

Re: Arrays passed by almost reference?

2009-11-05 Thread Bob Jones
"Leandro Lucarella" wrote in message news:20091106035612.gi3...@llucax.com.ar... >> >> I am not fully against pass-by-ref arrays, I just think in passing by >> reference all of the time could have some performance implications. > > OK, make 2 different types then: slices (value types, can't appe

Re: Arrays passed by almost reference?

2009-11-06 Thread Yigal Chripun
On 06/11/2009 07:07, Bob Jones wrote: "Leandro Lucarella" wrote in message news:20091106035612.gi3...@llucax.com.ar... I am not fully against pass-by-ref arrays, I just think in passing by reference all of the time could have some performance implications. OK, make 2 different types then: sl

Re: Arrays passed by almost reference?

2009-11-08 Thread Ali Cehreli
Andrei Alexandrescu Wrote: > Ali Cehreli wrote: > > I don't think that this is easy to explain to a learner; and I think that > > is a good indicator that there is a problem with these semantics. > > The ball is in your court to define better semantics. > > Andrei I thought I passed the ball

Re: Arrays passed by almost reference?

2009-11-12 Thread gzp
You can create DynamicArray and RandomAccessRange already now. Currently int[] a is very intuitive in its purpose, its just some of the implementation details that get confusing. int doSomething(in int[]) a) tells me doSomething is going to process an int array of any size and not modify it

Re: Arrays passed by almost reference?

2009-11-12 Thread Ali Cehreli
gzp Wrote: > I think problem is that, dynamic arrays and slices are NOT the same. I agree with most of what you wrote, but I can't see that in the current implementation. > They have a common subset of interfaces (length, at, slice(maybe)), but > they are just different. An array owns it's el

Re: Arrays passed by almost reference?

2009-11-13 Thread gzp
D2's "slice" is different than some other languages'. :) It's okay to change/create new semantics for new languages. It's a must have to develop new features as long as they make sense. But think as a newbie to programming for a while. If you've just learned of arrays and slices and hardly kn