Adding Arrays

BlitzMax Forums/BlitzMax Beginners Area/Adding Arrays

Otus(Posted 2008) [#1]
I never tried to add arrays before, assuming it would just give a syntax error. Strangely, it does not. Not that it seems to do anything at all.

SuperStrict

Local x:Int[] = [1,2]
Local y:Int[] = [2,-1]

x:+y	'???

Print x[0]+","+x[1]	'Prints "1,2"


Should this syntax do anything, or was my initial guess correct?

I find it weird it's not a syntax error, if I'm not supposed to do that.


Dreamora(Posted 2008) [#2]
There is no reason this should not work. x[0] refers to an integer, same for x[1]
and both is automatically converted to strings.


ImaginaryHuman(Posted 2008) [#3]
You might possibly be adding the Int Pointer of the Y array to the Int Pointer of the X array?


SebHoll(Posted 2008) [#4]
Aren't you just concatenating arrays x and y? I.e. you should end up with x[] having 4 elements [1,2,2,-1] after the line x:+y.

Test Code
SuperStrict

Local x:Int[] = [1,2]
Local y:Int[] = [2,-1]

x:+y	'???

For Local i% = 0 Until x.length
	Print "x[" + i + "]: " + x[i]
Next
BlitzMax Output on Windows
Linking:untitled1.debug.exe
Executing:untitled1.debug.exe
x[0]: 1
x[1]: 2
x[2]: 2
x[3]: -1
Array concatenation was added in BlitzMax v1.26 (see Versions.doc in the BlitzMax installation directory).


Dreamora(Posted 2008) [#5]
thats not what he did up there.


Sure it would concatenate but he just outputed the content of the fields.


Czar Flavius(Posted 2008) [#6]
I think he expected that y[0] would be added to x[0] and so on.


Otus(Posted 2008) [#7]
Thanks for clarifying. I indeed thought it would either add the fields one by one or do nothing. Should have guessed it would concatenate, or at least I should have tried.