s LearnSqueak.com

ABSOLUTE BEGINNER

Your first Symbol: give a name to an idea

Recognize a Symbol, turn it into text and compare names in five small Squeak steps.

5 minutes · 5 small steps · Squeak 6.1

STEP 1

Write a name

Open a Workspace from Squeak’s desktop menu: open… then workspace. Type this line, select it, right-click and choose print it (p). Some setups use middle-click.

The # makes a Symbol: a name you can pass around in your program. It does not run a command.

Select the whole line → print it (p)
#ready
NATIVE SQUEAK CAPTURE
Native Squeak Workspace evaluating #ready with selected answer #ready.
Actual Workspace Print it result: #ready.
You should see

#ready

STEP 2

Turn the name into text

Replace ALL the old text, including its printed answer. Select this new line and Print it.

asString gives ordinary text. Notice the quotes instead of # in the answer.

Select the whole line → print it (p)
#ready asString
NATIVE SQUEAK CAPTURE
Native Squeak Workspace evaluating #ready asString with selected answer 'ready'.
Actual Workspace Print it result: 'ready'.
You should see

'ready'

STEP 3

Turn text into a name

Replace all the text again, select this line and Print it.

asSymbol turns the text into a Symbol. You can go in either direction.

Select the whole line → print it (p)
'ready' asSymbol
NATIVE SQUEAK CAPTURE
Native Squeak Workspace evaluating 'ready' asSymbol with selected answer #ready.
Actual Workspace Print it result: #ready.
You should see

#ready

STEP 4

Compare different names

Replace all the text, select this line and Print it.

The = asks whether these names are equal. They are different, so the answer is false.

Select the whole line → print it (p)
#ready = #done
NATIVE SQUEAK CAPTURE
Native Squeak Workspace evaluating #ready = #done with selected answer false.
Actual Workspace Print it result: false.
You should see

false

STEP 5

Find the same name again

Replace all the text, select this line and Print it.

The comma joins two pieces of text. asSymbol finds the name ready again. Here == asks whether both sides are the very same object, and the answer is true.

Select the whole line → print it (p)
#ready == ('rea', 'dy') asSymbol
NATIVE SQUEAK CAPTURE
Native Squeak Workspace evaluating #ready == ('rea', 'dy') asSymbol with selected answer true.
Actual Workspace Print it result: true.
You should see

true

YOU DID IT

A name you can use.

A Symbol is useful for a fixed name such as ready or done. Ordinary text is still the right choice for a sentence you want to edit. Use = for a general value comparison; == specifically asks about the same object.

Try #waiting asString and then 'waiting' asSymbol. Replace the old result each time. Do not try to edit a Symbol’s characters.

Optional code download: open it as text and copy one example into Workspace.

Five Symbol examples: copy one at a time (.st)

Pair a name with a value · Try ordinary text · Official Squeak documentation