Characters, Strings and Symbols
Damien Cassou, Stéphane Ducasse and Luc Fabresse
http://stephane.ducasse.free.fr
What You Will Learn
- Characters
- Strings: a collection of characters
- Symbols: unique strings
Characters
- Characters:
- Unprintable characters:
Character space
, Character tab
, Character cr
'Strings'
Delimited by '
A String: a Collection of Characters
Quote in Strings
- To add a quote in a string with just type it twice
- Pay attention there is only one element
Getting the Last Char
Ways to Obtain a String
For Concatenation Use ,
Take Care With ,
Message comma #,
copies strings so multiple concatenations can generate useless intermediate versions
- Benchmark it
- If this is worth, use a stream to avoid creating multiple intermediary strings
Symbols
#calvin
is a symbol
- A kind of string
- Unique in the system
- Starts with
#
#class
#mac
#at:put:
#+
#accept:
Symbols are Unique
Two symbols with the same representation points to the same object
Two strings with the same representation may be different objects depending on compiler optimisations
Symbols vs. Strings
- A symbol is a read-only and unique object
- A string is a mutable object (for now)
- Symbols are used as method selectors
- Symbols are good candidates for identity based dictionaries (
IdentityDictionary
)
What You Should Know
- Strings are collections of characters
- Symbols are unique immutable strings
/