点'。'在Smalltalk中

问题描述 投票:-1回答:1

Smalltalk中.的用法是什么?根据我的理解,它是不同语句的分隔符,但是如果语句末尾可以省略。正确吗?

smalltalk pharo
1个回答
0
投票

.是一个语句分隔符,类似于;中的C(通常在行尾使用)。原因是英语中的普通句子以.结尾。

可以省略的地方是:

  1. 变量定义

  2. 评论

  3. 一个语句块(块中的最后一条语句)

  4. 方法末尾

Smalltalk / X中的示例方法:

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       
© www.soinside.com 2019 - 2024. All rights reserved.