목ì � ¶
- SBPP를 공부하기 위해 최소한ì�˜ 문법ì�€ ë–¼ì•¼í•˜ê² ë‹¤ëŠ” ìƒ�ê°�ì�´ 들었다.
기본 문법 ¶
~cpp ClassName>>methodName.
- ì‹¤ì œë¡œ ì“°ì�´ëŠ” 문법ì�€ 아니다. 하지만, Smalltlak 설명ì—�서 해당 메소드가 ì–´ë””ì—�서 발현ë�˜ëŠ”ì§€ë¥¼ 알수 있게 만들어 준다.
- Debug 모드�서 메세지� �름� 나타낼때� �용�다.
- ì‹¤ì œë¡œ ì“°ì�´ëŠ” 문법ì�€ 아니다. 하지만, Smalltlak 설명ì—�서 해당 메소드가 ì–´ë””ì—�서 발현ë�˜ëŠ”ì§€ë¥¼ 알수 있게 만들어 준다.
~cpp 배울때 가장 �주 보는 �러 메시지 UndifinedObject(Object)>>doesNotUnderstand:
~cpp a := 1. b := OrderedCollection new.
~cpp
Money class>>amout: anAmount
self new setAmount: anAmount.
~cpp
TempTestCase>>initialize
super initialize.
~cpp
a := OrderdCollection new
add: 10;
add: 1;
add; 9;
yourself.
~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"
- ì„ íƒ�ìž�는 단ì�¼ ì‹�별ìž�ì�´ë©°, ì�¸ìˆ˜ëŠ” 없다.(the selector is a single Identifier, there are no arguments)
- 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"
- ì„ íƒ�ìž�는 íŠ¹ì •í•œ 기호(하나나 둘ì�´ìƒ�ì�˜ 문ìž�, 숫ìž�ê°€ 아님)ì�´ê³ , ì�¸ìˆ˜ê°€ ë”± 하나만 있다.(the selector is one or two non-alphanumeric characters, followed by exactly one argument object)
- 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"
- 키워드란 ì½œë¡ (:)ì�´ ë’¤ì—� 붙는 ì‹�별ìž�ì�´ë‹¤.(a keyword is an Identifier followed by colon ":" )
ì‹ ê¸°í•œì � ¶
2 + 3 * 6 � 몇�까?
ì�¼ë°˜ì �으로는 20ì�´ê² 지만 SmallTalkì—�서는 30ì�´ë‹¤.--; ì—´ë�¼ ì‹ ê¸°í•˜ë‹¤.
ì�½ì�€ì§€ 얼마 안ë�˜ì—ˆëŠ”ë�°ë�„ ìŠ¤ëª°í† í�¬ì�˜ 메소드 길ì�´ëŠ” 7줄ì�„ 넘지 않는다는 ë§�ì�´ 나온다. 그러면서 extract method(ì�´ ë§�ì�„ ì§�ì ‘ì �으로 ì“°ì§„ 않았지만)ë�„ 나온다.
ë¦¬íŒ©í† ë§� ê´€ë ¨ 문구 계ì†� ë‚˜ì˜¤ê³ ìžˆë‹¤.
컨테ì�´ë„ˆ 리턴하는 메소드는 앞ì—� as를 ë¶™ì�¸ë‹¤. ì�´ê²ƒë�„ ì�¨ë¨¹ì–´ì•¼ê² 다.
ë¦¬íŒ©í† ë§� ê´€ë ¨ 문구 계ì†� ë‚˜ì˜¤ê³ ìžˆë‹¤.
컨테ì�´ë„ˆ 리턴하는 메소드는 앞ì—� as를 ë¶™ì�¸ë‹¤. ì�´ê²ƒë�„ ì�¨ë¨¹ì–´ì•¼ê² 다.
Message ì�˜ ì „ë‹¬ 순서 ¶
from Smalltalk by Example
- 메세지는 왼쪽�서 오른쪽으로 진행한다. Evaluation is done left to right.
- 그래서 2 + 3 * 6 -> 30
- 그래서 2 + 3 * 6 -> 30
- Unary 메세지는 가장 높ì�€ ìš°ì„ ìˆœìœ„ë¥¼ 가진다. messages have the highest precedence.
- Binary 메세지는 ê·¸ 다ì�Œì�˜ ìš°ì„ ìˆœìœ„ë¥¼ 가진다. Binary message have the next precedence.
- Keyword 메세지는 가장 ë‚®ì�€ ìš°ì„ ìˆœìœ„ë¥¼ 가진다.Keyword message have the lowest precedence.
- 괄호 '()' 를 ì�¨ì„œ ìš°ì„ ìˆœìœ„ë¥¼ ë³€ê²½í• ìˆ˜ 있다. You can alter precedence by using parenthses.
Smalltalk










