Skip to content
This repository has been archived by the owner on Nov 23, 2020. It is now read-only.

Array Concatenation #18

Open
CodaFi opened this issue Dec 18, 2013 · 6 comments
Open

Array Concatenation #18

CodaFi opened this issue Dec 18, 2013 · 6 comments

Comments

@CodaFi
Copy link

CodaFi commented Dec 18, 2013

For the concat example, it would be trivial to create a loop and just copy the values onto the end of the first array, but there are some opportunities for a concat operator to be built into the language:

  1. ..= The dedicated concat operator for strings could be overloaded to work with arrays, as in:
var array1 = array(1, 2, 3);
array1 ..= array(1, 2, 3,);
  1. A concat() function built into the STL as in:
var array = concat(array1, array2);
  1. += could be overloaded as in:
var array1 = array(1, 2, 3);
array1 += array(1, 2, 3,);

All of which would need to be mirrored in the implementation with some kind of spn_array_concat(..);.

@H2CO3
Copy link
Owner

H2CO3 commented Dec 18, 2013

Yay! An stdlib function seems reasonable.

@CodaFi
Copy link
Author

CodaFi commented Dec 18, 2013

Ah, wait, because strings and arrays are (sort of) the same in the repl, shouldn't join() work?

@H2CO3
Copy link
Owner

H2CO3 commented Dec 18, 2013

Just because I know your background: join is a less fancy name for componentsJoinedByString: :P So, no.

@CodaFi
Copy link
Author

CodaFi commented Dec 19, 2013

OK. Then I didn't just make a new feature branch for this for nothing :)

@C0deH4cker
Copy link

I personally prefer option 1 and believe it would be easiest to understand (since .. means concatenate in other parts of the language). I would also like to propose another suggestion:

var array1 = array(1, 2, 3);
var array2 = array(4, 5, 6);
array1.append(array2);

So array1 would now contain [1, 2, 3, 4, 5, 6]. This is based off of Python, where you can do list1.append(list2).

@H2CO3
Copy link
Owner

H2CO3 commented Feb 3, 2014

Yup, and strings are very similar to arrays in many other aspects as well... (maybe I should make the indexof() standard library function accept arrays too.)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants