www.digitalmars.com         C & C++   DMDScript  

D - Idea I had while coding, not sure if it's unrealistic in a strongly type language...

reply "Bradeeoh" <bradeeoh crosswinds.net> writes:
If so, please tell me how unrealistic, just throwing out the idea.

Built-in array concatination.

byte[] b = new byte[3];
byte[] c = new byte[5];
byte[] d = b + c;
( d is now a new byte[], an empty byte[8] )

int[] e = new int[10];
d = c + e;    // error - can't mix byte[] and int[]

The idea is simple.  It just came up while working and I hit a particularly
nasty pocket of objects.

Of course, libraries could provide this sevice (not this nicely without
operator overloading...) and I've written my own libraries in both C++ and
Java to accomplish it.  But instead of calling functions, why not treat
arrays like Strings as far as simple '+' concatination goes?

I will admit that I didn't check the language spec before posting this
because I'm working and I can't take much time out.  I don't REMEMBER it
being there...  if it is already, I applaud Walter once again and return to
work gracefully.

If not, then any thoughts?

-Brady
Aug 28 2001
next sibling parent reply Dan Hursh <hursh infonet.isl.net> writes:
Bradeeoh wrote:
 
 If so, please tell me how unrealistic, just throwing out the idea.
 
 Built-in array concatination.
 
 byte[] b = new byte[3];
 byte[] c = new byte[5];
 byte[] d = b + c;
 ( d is now a new byte[], an empty byte[8] )
 
 int[] e = new int[10];
 d = c + e;    // error - can't mix byte[] and int[]
 
 The idea is simple.  It just came up while working and I hit a particularly
 nasty pocket of objects.
 
 Of course, libraries could provide this sevice (not this nicely without
 operator overloading...) and I've written my own libraries in both C++ and
 Java to accomplish it.  But instead of calling functions, why not treat
 arrays like Strings as far as simple '+' concatination goes?
 
 I will admit that I didn't check the language spec before posting this
 because I'm working and I can't take much time out.  I don't REMEMBER it
 being there...  if it is already, I applaud Walter once again and return to
 work gracefully.
 
 If not, then any thoughts?
 
 -Brady
Actually, when I read the spec the first time I got the idea that: array0 = array1 + array2 for array's of the same size (that was required) meant: for(int i=0; i < array.length; i++) array0[i] = array1[i] + array2[i]; and I figured it was good that at least array addition would look like addition. When trying to verify my belief I reread the spec and mournfully convinced myself that it was array concatenation. I guess I'd like to know which is it. Dan
Aug 28 2001
parent reply nicO <nicolas.boulay ifrance.com> writes:
Dan Hursh a écrit :
 
 Bradeeoh wrote:
 If so, please tell me how unrealistic, just throwing out the idea.

 Built-in array concatination.

 byte[] b = new byte[3];
 byte[] c = new byte[5];
 byte[] d = b + c;
 ( d is now a new byte[], an empty byte[8] )

 int[] e = new int[10];
 d = c + e;    // error - can't mix byte[] and int[]

 The idea is simple.  It just came up while working and I hit a particularly
 nasty pocket of objects.

 Of course, libraries could provide this sevice (not this nicely without
 operator overloading...) and I've written my own libraries in both C++ and
 Java to accomplish it.  But instead of calling functions, why not treat
 arrays like Strings as far as simple '+' concatination goes?

 I will admit that I didn't check the language spec before posting this
 because I'm working and I can't take much time out.  I don't REMEMBER it
 being there...  if it is already, I applaud Walter once again and return to
 work gracefully.

 If not, then any thoughts?

 -Brady
Actually, when I read the spec the first time I got the idea that: array0 = array1 + array2 for array's of the same size (that was required) meant: for(int i=0; i < array.length; i++) array0[i] = array1[i] + array2[i]; and I figured it was good that at least array addition would look like addition. When trying to verify my belief I reread the spec and mournfully convinced myself that it was array concatenation. I guess I'd like to know which is it. Dan
Maybe we could introduice new operator as '.' (dot) or 'concat'. So introduice some other built-in operator. C introduice too few operator, we should add '**' or '^' for power. nicO nicO
Sep 01 2001
parent reply "kaffiene" <kaffiene xtra.co.nz> writes:
 Actually, when I read the spec the first time I got the idea that:

         array0 = array1 + array2

 for array's of the same size (that was required) meant:

         for(int i=0; i < array.length; i++)
                 array0[i] = array1[i] + array2[i];

 and I figured it was good that at least array addition would look like
 addition.  When trying to verify my belief I reread the spec and
 mournfully convinced myself that it was array concatenation.  I guess
 I'd like to know which is it.

 Dan
Maybe we could introduice new operator as '.' (dot) or 'concat'. So introduice some other built-in operator. C introduice too few operator, we should add '**' or '^' for power.
^ is already used in C.
Sep 02 2001
parent reply Dan Hursh <hursh infonet.isl.net> writes:
kaffiene wrote:
 
  >
 Actually, when I read the spec the first time I got the idea that:

         array0 = array1 + array2

 for array's of the same size (that was required) meant:

         for(int i=0; i < array.length; i++)
                 array0[i] = array1[i] + array2[i];

 and I figured it was good that at least array addition would look like
 addition.  When trying to verify my belief I reread the spec and
 mournfully convinced myself that it was array concatenation.  I guess
 I'd like to know which is it.

 Dan
Maybe we could introduice new operator as '.' (dot) or 'concat'. So introduice some other built-in operator. C introduice too few operator, we should add '**' or '^' for power.
^ is already used in C.
For that matter, ** won't work because the is already an infix and binary * operator. x ** y => x * (*y) I agree with the idea though. I like perl because of it's liberal use of infix and unary operations. I like C++ because it let me do the same, but it would be nice to have more operator symbol at my disposal, and to be and to mess with precedence. Since before first grade we are taught infix operations. They feel much more natural for anything remotely numeric. Dan
Sep 02 2001
parent Axel Kittenberger <axel dtone.org> writes:
 For that matter, ** won't work because the is already an infix and
 binary * operator.
 
 x ** y  =>  x * (*y)
C is already broken in this regard: x /* y => x / (*y) Right? No, it's a comment :o) - Axel
Sep 02 2001
prev sibling parent "Walter" <walter digitalmars.com> writes:
It's already there in the language <g>. -Walter

Bradeeoh wrote in message <9mfme5$v1g$1 digitaldaemon.com>...
If so, please tell me how unrealistic, just throwing out the idea.

Built-in array concatination.

byte[] b = new byte[3];
byte[] c = new byte[5];
byte[] d = b + c;
( d is now a new byte[], an empty byte[8] )

int[] e = new int[10];
d = c + e;    // error - can't mix byte[] and int[]

The idea is simple.  It just came up while working and I hit a particularly
nasty pocket of objects.

Of course, libraries could provide this sevice (not this nicely without
operator overloading...) and I've written my own libraries in both C++ and
Java to accomplish it.  But instead of calling functions, why not treat
arrays like Strings as far as simple '+' concatination goes?

I will admit that I didn't check the language spec before posting this
because I'm working and I can't take much time out.  I don't REMEMBER it
being there...  if it is already, I applaud Walter once again and return to
work gracefully.

If not, then any thoughts?

-Brady
Sep 01 2001