ABSOLUTE BEGINNER
Your first isEmpty: ask whether anything is there
Ask a word or list whether it contains anything, then watch a collection change in five tiny visual Squeak steps.
STEP 1
Ask an empty piece of text
Open a Workspace from the World menu: open..., workspace. Type two single quotes with nothing between them. Select the whole expression and choose Print it. isEmpty asks whether the text contains zero characters.
'' isEmpty
true. The empty text is a real object, and it has no characters.
STEP 2
Put something between the quotes
Now the text holds two characters. The same question can have a different answer because the receiver is different.
'Hi' isEmpty
false. Try a single space between the quotes. That also answers false, because a space is one character.
STEP 3
Ask an empty list
The notation #() makes an empty Array. You can send isEmpty to this collection too. You do not have to count its entries yourself.
#() isEmpty
true. The list contains no entries. An empty list and empty text are different kinds of object, but both understand this message.
STEP 4
Keep zero separate from empty
This list contains one number. That number happens to be zero. The value of an entry is different from the number of entries.
#(0) isEmpty
false. There is one entry. Try #(nil): it also answers false, because that list contains one entry too.
STEP 5
Watch a list become empty again
Copy all the lines, including the bars. OrderedCollection is a list whose size can change. We ask before adding a number, after adding it, and after removing it. The final braces collect the three answers.
| basket before during after |
basket := OrderedCollection new.
before := basket isEmpty.
basket add: 7.
during := basket isEmpty.
basket remove: 7.
after := basket isEmpty.
{before. during. after}
#(true false true). Empty, then occupied, then empty again. isEmpty reports the current contents of the collection.
YOU DID IT
A small step. A real result.
isEmpty asks whether a collection has zero entries. A zero, a space, or nil inside a collection still counts as an entry.
Optional code download: open it as text and copy one example into Workspace.