digitalmars.D - Proposal: Reference Variables
- S. Chancellor (19/19) Apr 06 2006 I would like to suggest the following variable type added to D as a
- Hasan Aljudy (4/38) Apr 07 2006 While I like the idea of references and refernce semantics for things
- Bruno Medeiros (7/46) Apr 09 2006 What do you mean "reference semantics"? "References" (as in "reference
- Hasan Aljudy (4/52) Apr 10 2006 Maybe I don't understand the meaning of "semantics"!
- Bruno Medeiros (9/43) Apr 09 2006 I would moderately prefer a syntax with "ref" instead of "&", as:
- Hong (2/10) Apr 10 2006
I would like to suggest the following variable type added to D as a supplement to pointers. Please review the following code and suggest modifications and additions as you see. Thanks! -S. Oh yes, and please assume all the following asserts PASS. long x = 2; long& y = &x; assert(y == 2); y = 4; assert(x == 4); assert(&y == &x); //Notice the change in the operation of &. Not a handle to x! long z = 5; &y = &z; //& Allows l-value assignment, assert( y == 5 ); assert( &y == &z ); assert(y.sizeof == z.sizeof); //Sizeof gives information on referenced type, not reference. Ditto for other properties
Apr 06 2006
S. Chancellor wrote:I would like to suggest the following variable type added to D as a supplement to pointers. Please review the following code and suggest modifications and additions as you see. Thanks! -S. Oh yes, and please assume all the following asserts PASS. long x = 2; long& y = &x; assert(y == 2); y = 4; assert(x == 4); assert(&y == &x); //Notice the change in the operation of &. Not a handle to x! long z = 5; &y = &z; //& Allows l-value assignment, assert( y == 5 ); assert( &y == &z ); assert(y.sizeof == z.sizeof); //Sizeof gives information on referenced type, not reference. Ditto for other propertiesWhile I like the idea of references and refernce semantics for things like structs and whatnot, I think the C++ & operator is the *wrong* way to do it.
Apr 07 2006
Hasan Aljudy wrote:S. Chancellor wrote:What do you mean "reference semantics"? "References" (as in "reference variables, "alias references", or "c++ references") do not give "reference semantics", (as in "reference types"). -- Bruno Medeiros - CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#DI would like to suggest the following variable type added to D as a supplement to pointers. Please review the following code and suggest modifications and additions as you see. Thanks! -S. Oh yes, and please assume all the following asserts PASS. long x = 2; long& y = &x; assert(y == 2); y = 4; assert(x == 4); assert(&y == &x); //Notice the change in the operation of &. Not a handle to x! long z = 5; &y = &z; //& Allows l-value assignment, assert( y == 5 ); assert( &y == &z ); assert(y.sizeof == z.sizeof); //Sizeof gives information on referenced type, not reference. Ditto for other propertiesWhile I like the idea of references and refernce semantics for things like structs and whatnot, I think the C++ & operator is the *wrong* way to do it.
Apr 09 2006
Bruno Medeiros wrote:Hasan Aljudy wrote:Maybe I don't understand the meaning of "semantics"! What I mean by "Reference semantics" is reference behavior applied to pointers. (if that makes it any clearer ..)S. Chancellor wrote:What do you mean "reference semantics"? "References" (as in "reference variables, "alias references", or "c++ references") do not give "reference semantics", (as in "reference types").I would like to suggest the following variable type added to D as a supplement to pointers. Please review the following code and suggest modifications and additions as you see. Thanks! -S. Oh yes, and please assume all the following asserts PASS. long x = 2; long& y = &x; assert(y == 2); y = 4; assert(x == 4); assert(&y == &x); //Notice the change in the operation of &. Not a handle to x! long z = 5; &y = &z; //& Allows l-value assignment, assert( y == 5 ); assert( &y == &z ); assert(y.sizeof == z.sizeof); //Sizeof gives information on referenced type, not reference. Ditto for other propertiesWhile I like the idea of references and refernce semantics for things like structs and whatnot, I think the C++ & operator is the *wrong* way to do it.
Apr 10 2006
S. Chancellor wrote:I would like to suggest the following variable type added to D as a supplement to pointers. Please review the following code and suggest modifications and additions as you see. Thanks! -S. Oh yes, and please assume all the following asserts PASS. long x = 2; long& y = &x; assert(y == 2); y = 4; assert(x == 4); assert(&y == &x); //Notice the change in the operation of &. Not a handle to x! long z = 5; &y = &z; //& Allows l-value assignment, assert( y == 5 ); assert( &y == &z ); assert(y.sizeof == z.sizeof); //Sizeof gives information on referenced type, not reference. Ditto for other propertiesI would moderately prefer a syntax with "ref" instead of "&", as: long x = 1; ref long z = &x; Also, "ref" (or "&") would supersede the functionality of "inout", since they do the same, only that "inout" only works for parameter variables. -- Bruno Medeiros - CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
Apr 09 2006
ref/alias/inout are possible choices. It seems impossible to write proper containers without C++ like reference typeI would moderately prefer a syntax with "ref" instead of "&", as: long x = 1; ref long z = &x; Also, "ref" (or "&") would supersede the functionality of "inout", since they do the same, only that "inout" only works for parameter variables. -- Bruno Medeiros - CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
Apr 10 2006