This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-09-12 13:44:10

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Lists in Squeak

I know you can make lists like this:
aVariable := #(list items here)

But how do I remove certain ones, like
remove item 2 of list


You can now reach me on Twitter @johnnydean1_

Offline

 

#2 2010-09-12 14:09:59

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Lists in Squeak

Use an OrderedCollection, like so:

|oc|
oc := {'array'.'array'.'array'} as: OrderedCollection.
oc removeAt: 2.
oc := #(symbol 'string' (array)) as: OrderedCollection.
oc removeLast; removeFirst; removeAll.


nXIII

Offline

 

#3 2010-09-12 14:11:07

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Lists in Squeak

and how to add to the lists and call values?


You can now reach me on Twitter @johnnydean1_

Offline

 

#4 2010-09-12 15:24:34

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Lists in Squeak

Look, just open a browser and go to "Collections-Sequencable" -> "OrderedCollection" and look for yourself.
I have absolutely no clue what you mean by "call values"


nXIII

Offline

 

#5 2010-09-12 15:26:33

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Lists in Squeak

nXIII wrote:

Look, just open a browser and go to "Collections-Sequencable" -> "OrderedCollection" and look for yourself.
I have absolutely no clue what you mean by "call values"

i think jd1 means like
list at: 1
or
list first

Offline

 

#6 2010-09-12 15:50:45

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Lists in Squeak

yes!


You can now reach me on Twitter @johnnydean1_

Offline

 

#7 2010-09-12 16:01:14

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Lists in Squeak

So im clear:

A ordered collection (list)
|oc|
oc := {'array'.'array'.'array'} as: OrderedCollection. "A OC"
oc removeAt: 2. "remove thing 2"
oc := #(symbol 'string' (array)) as: OrderedCollection. "What does this do?"
oc removeLast; removeFirst; removeAll.  "removing things"
oc at: 1. "Item 1 of oc"
oc first. "The first record in oc"

How do I add a new entry?

oc add: 'string' "Is this how?"
oc add: 'string' after: 'string to find' "Is this how I add something after something else"



Am I correct?


You can now reach me on Twitter @johnnydean1_

Offline

 

#8 2010-09-12 16:13:07

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Lists in Squeak

johnnydean1 wrote:

So im clear:

A ordered collection (list)
|oc|
oc := {'array'.'array'.'array'} as: OrderedCollection. "A OC"
oc removeAt: 2. "remove thing 2"
oc := #(symbol 'string' (array)) as: OrderedCollection. "What does this do?"
oc removeLast; removeFirst; removeAll.  "removing things"
oc at: 1. "Item 1 of oc"
oc first. "The first record in oc"

How do I add a new entry?

oc add: 'string' "Is this how?"
oc add: 'string' after: 'string to find' "Is this how I add something after something else"



Am I correct?

Yes. add: is equivalent to addLast: (add after the last index). There's also addFirst and add: afterIndex:


nXIII

Offline

 

#9 2010-09-12 16:13:37

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Lists in Squeak

Yay!


You can now reach me on Twitter @johnnydean1_

Offline

 

Board footer