U E D R , A S I H C RSS

Small Talk/문법정리

목�

  • SBPP를 공부하기 위해 최소한ì�˜ 문법ì�€ 떼야하겠다는 ìƒ�ê°�ì�´ 들었다.

기본 문법


  • ~cpp ClassName>>methodName.
    • 실제로 ì“°ì�´ëŠ” 문법ì�€ 아니다. 하지만, Smalltlak 설명ì—�서 해당 메소드가 ì–´ë””ì—�서 발현ë�˜ëŠ”ì§€ë¥¼ 알수 있게 만들어 준다.
    • Debug 모드ì—�서 메세지ì�˜ í��름ì�„ 나타낼때ë�„ ì�´ìš©ë�œë‹¤.

  • ~cpp 
    배울때 가장 �주 보는 �러 메시지
    UndifinedObject(Object)>>doesNotUnderstand:
    
  • := 대입 ì—°ì‚°ìž�
    ~cpp 
    a := 1.
    b := OrderedCollection new.
    
  • self : ìž�ì‹ ì�„ 지칭하는 참조
    ~cpp 
    Money class>>amout: anAmount
        self new setAmount: anAmount.
    
  • super : 부모를 지칭하는 참조
    ~cpp 
    TempTestCase>>initialize
        super initialize.
    
  • yourself : 해당 ê°�체를 지칭하는 참조
    ~cpp 
    a := OrderdCollection new
        add: 10;
        add: 1;
        add; 9;
        yourself.
    
  • ^ 리턴 : Smalltalk 모든 메소드는 리턴한다. Cì—�서와 ê°™ì�€ void는 없다. 그래서 명시ì �으로 리턴 안해주면 self를 리턴한다.
    ~cpp 
    Color>>alpha
        ...
        ^1.0
    

메시지 보내기

from VisualWorks Lesson Browser 01 (Lesson: Language Basic)
  • 모든 스몰토í�¬ 표현ì‹�ì�´ 다ì�Œê³¼ ê°™ì�€ ì–‘ì‹�ì�„ 따른다.All Smalltalk expressions follow the form:
  • anObject aMessage.
  • 예시)
    ~cpp 
    "Code in Bold"		"Comments in double-quotes"
    3 squared.		"Receiver object is small integer 3."
    			"The message sent is   #squared"
    
    'abc' asUppercase.	"Receiver object is string 'abc'."
    			"The message sent is   #asUppercase"
    
    200 factorial.		"Receiver object is small integer 200."
    			"The message sent is   #factorial"
    

메시지 종류

from VisualWorks Lesson Browser 01 (Lesson: Language Basic)
  • Unary messages
    • ì„ íƒ�ìž�는 단ì�¼ ì‹�별ìž�ì�´ë©°, ì�¸ìˆ˜ëŠ” 없다.(the selector is a single Identifier, there are no arguments)
    • 예시)
      ~cpp 
      3 negated			"selector is  #negated"
      'abcdefg' reverse		"selector is  #reverse"
      
  • Binary messages
    • ì„ íƒ�ìž�는 특정한 기호(하나나 둘ì�´ìƒ�ì�˜ 문ìž�, 숫ìž�ê°€ 아님)ì�´ê³ , ì�¸ìˆ˜ê°€ ë”± 하나만 있다.(the selector is one or two non-alphanumeric characters, followed by exactly one argument object)
    • 예시)
      ~cpp 
      3 + 5				"selector is  #+"
      				"argument is the Integer object 5"
      'abc' , 'xyz'			"selector is  #,  (comma character)"
      				"argument is the String 'xyz'"
      20 <= 20			"selector is  #<="
      				"argument is the Integer object 20"
      
  • Keyword messages
    • 키워드란 콜론(:)ì�´ ë’¤ì—� 붙는 ì‹�별ìž�ì�´ë‹¤.(a keyword is an Identifier followed by colon ":" )
    • ê°� 키워드ì—� ì�¸ìˆ˜ê°€ 있ì�„ 때, ì„ íƒ�ìž�는 하나 ì�´ìƒ�ì�˜ 키워드ì�´ë‹¤.(the selector is one or more keywords, when called each keyword is followed by an argument object) -> 세번째 예시 참고
    • 예시)
      ~cpp 
      3 raisedTo: 17.			"selector is  #raisedTo:"
      				"argument is 17"
      3 between: 5 and: 10.		"selector is  #between:and:"
      				"arguments are 5 and 10"
      Point x: 4 y: 200. 		"receiver is the object Point"
      				"selector is  #x:y"
      				"arguments are 4 and 200"
      

신기한�

2 + 3 * 6 � 몇�까?
�반�으로는 20�겠지만 SmallTalk�서는 30�다.--; 열� 신기하다.

��지 얼마 안�었는�� 스몰토�� 메소드 길�는 7줄� 넘지 않는다는 �� 나온다. 그러면서 extract method(� �� �접�으로 쓰진 않았지만)� 나온다.

리팩토� 관련 문구 계� 나오고 있다.
컨테�너 리턴하는 메소드는 앞� as를 붙�다. �것� �먹어야겠다.

Message � 전달 순서

from Smalltalk by Example
  1. 메세지는 왼쪽�서 오른쪽으로 진행한다. Evaluation is done left to right.
    • 그래서 2 + 3 * 6 -> 30
  2. Unary 메세지는 가장 높� 우선 순위를 가진다. messages have the highest precedence.
  3. Binary 메세지는 그 다�� 우선 순위를 가진다. Binary message have the next precedence.
  4. Keyword 메세지는 가장 낮� 우선 순위를 가진다.Keyword message have the lowest precedence.
  5. 괄호 '()' 를 �서 우선 순위를 변경할수 있다. You can alter precedence by using parenthses.

Smalltalk
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:28:03
Processing time 0.0062 sec