What exacly is the usage of .
in Smalltalk? Based on my understanding, it is the separator of different statements, but can be omitted if statement is at the end. Is that correct?
The .
is a statement separator like ;
in Pascal
(usually used at the end of lines). The motivation (reason) being that the ordinary sentences in English end with .
.
The places it must/could be omitted are:
Variable definition
Comments
One statement block or last statement at the block
At the end of a method
When you define a #selector
or #selector: message
An example method from Smalltalk/X-jv:
selectorAsRegistryName: aSelector
"Splits selector into string words with spaces.
For example: itemName becomes 'Item Name'"
| registryName selectorCollection |
registryName := String new.
selectorCollection := aSelector asCollectionOfSubCollectionsSeparatedByAnyForWhich:[:ch | ch isUppercase ] withSeparatorsIncluded:true.
selectorCollection at: 1 put: selectorCollection copy first asUppercaseFirst. "/ first string must be uppercase too
selectorCollection do: [ :eachString |
registryName := registryName isEmpty ifTrue: [ eachString ]
ifFalse: [ registryName, Character space, eachString ]
].
^ registryName
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With