Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Usage of dot '.' in Smalltalk

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?

like image 893
laike9m Avatar asked Jan 07 '20 08:01

laike9m


Video Answer


1 Answers

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:

  1. Variable definition

  2. Comments

  3. One statement block or last statement at the block

  4. At the end of a method

  5. 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       
like image 147
tukan Avatar answered Sep 20 '22 11:09

tukan