Kobojunkie
Kobojunkie

Reputation: 6555

How to, in smalltalk,append two arrays

Had to change this up. I have two arrays and I want to essentially concatenate them into one array.

 completearray:= completearray, temparray."concatenate the new array to the existing one"

How do I get this working please? Thanks.

Upvotes: 1

Views: 3852

Answers (4)

Karsten
Karsten

Reputation: 2433

if your code doesn't run, you probably don't have an Array object in "completearray", but instead have an object that doesn't respond to #, (i.e. nil doesn't respond to #,).

Upvotes: 1

Mekanik
Mekanik

Reputation: 2562

I don't know, why it may not work in your version of VisualWorks, but you can try to do this:

completearray addAll: temparray.

Source, just in case:

addAll: collection
    ^ collection
        do: [ :element | self add: element];
        yourself

Upvotes: 0

Sean DeNigris
Sean DeNigris

Reputation: 6390

Your code works in Squeak, so what is the problem?

anArray := #(1 2 3 4).
anotherArray := #(5 6 7).
anArray, anotherArray "Returns #(1 2 3 4 5 6 7)"

Upvotes: 8

Christian Haider
Christian Haider

Reputation: 1

you are adding a character ($,), but you have to add a string with #, (cancat). try: yourString , ','

Upvotes: 0

Related Questions