Squeak - Sizuha/devdog GitHub Wiki

Install

๊ธฐ๋ณธ ์กฐ์ž‘

Workspace

  • Command + D: do it. ๋ธ”๋Ÿญ์œผ๋กœ ์ง€์ •๋œ ๋ถ€๋ถ„์„ ์‹คํ–‰.
  • Command + P: print it. ๋ธ”๋Ÿญ์œผ๋กœ ์ง€์ •๋œ ๋ถ€๋ถ„์„ ์‹คํ–‰ํ•˜๊ณ  ๊ฒฐ๊ณผ๊ฐ’์„ ๋ฐ”๋กœ Workspace์— ํ‘œ์‹œ.
  • Command + I: inspect it.

Transcript

Transcript ์œˆ๋„์šฐ๋Š” TranscriptStream ํƒ€์ž… ๊ฐ์ฒด๋กœ ''Transcript''๋ผ๋Š” ์œ ์ผํ•œ ์ธ์Šคํ„ด์Šค๋กœ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋‹ค.

Transcript show: 'Text Message'. "Transcript์ฐฝ์— ๋ฉ”์„ธ์ง€๋ฅผ ํ‘œ์‹œ"
Transcript showln: 'Text Message'. "Transcript์ฐฝ์— ๋ฉ”์„ธ์ง€๋ฅผ ํ‘œ์‹œํ•˜๊ณ  ๊ฐœํ–‰."
Transcript clear. "Transcript์ฐฝ์˜ ๋‚ด์šฉ์„ ์ง€์šด๋‹ค."

ํด๋ž˜์Šค ์ƒ์„ฑ

ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ ๋‹ค๋Š” ๊ฒƒ์€, ์–ด๋–ค ์‹์œผ๋กœ๋“  ๋ชจ์ฒด๊ฐ€ ๋˜๋Š” ํด๋ž˜์Šค๋กœ๋ถ€ํ„ฐ ํ•˜์œ„ ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ ๋‹ค๋Š” ๊ฐœ๋….

๋ชจ์ฒด๊ฐ€ ๋˜๋Š” ํด๋ž˜์Šค์— subclass ๋ฉ”์„ธ์ง€๋ฅผ ๋‚ ๋ ค์„œ ์ƒˆ๋กœ์šด ํ•˜์œ„ ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค.

"Integer ํด๋ž˜์Šค์˜ ์ •์˜"
Number subclass: #Integer
  instanceVariableNames: '' "์ธ์Šคํ„ด์Šค ๋ณ€์ˆ˜"
  classVariableNames: 'LowBitPerByteTable' "ํด๋ž˜์Šค ๋ณ€์ˆ˜"
  poolDictionaries: ''
  category: 'Kernel-Numbers'

๋ฉ”์†Œ๋“œ ์ƒ์„ฑ

System Browser์˜ UI๋ฅผ ์ด์šฉํ•ด์„œ ์ƒ์„ฑํ•˜๋Š”๊ฒŒ ๊ฐ„๋‹จํ•˜๋‹ค.

๋ฉ”์„œ๋“œ ๋ฆฌ์ŠคํŠธ์˜ ๋นˆ ๋ถ€๋ถ„์„ ํด๋ฆญํ•˜๋ฉด, ๋ฉ”์†Œ๋“œ ๋‚ด์šฉ ํ‘œ์‹œ๊ฐ€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋‚˜์˜ค๋Š”๋ฐ, ์ด ๋‚ด์šฉ์„ ์ˆ˜์ •ํ•œ ํ›„์— Command + S ๋กœ ์ €์žฅํ•˜๋ฉด ๋œ๋‹ค.

messageSelectorAndArgumentNames
  "comment stating purpose of message"

  | temporary variable names |
  statements

๋ฉ”์†Œ๋“œ ์ œ๊ฑฐ

Class removeSelector: #selector

์˜ˆ์™ธ์ฒ˜๋ฆฌ

์—๋Ÿฌ๋ฐœ์ƒ ํ™•์ธ

[123 / 0] ifError: [ :err | Transcript clear; show: err. ].

์˜ˆ์™ธ ํ™•์ธ

[ ... ] on: ์˜ˆ์™ธํด๋ž˜์Šค do: [ ์˜ˆ์™ธ์ฒ˜๋ฆฌ ๋‚ด์šฉ. ]

[123 / 0] on: ZeroDivide do: [ Transcript clear; show: 'Catch Error: Zero Divide'. ].

์˜ˆ์™ธ ๋˜์ง€๊ธฐ

์ž„์˜๋กœ ์˜ˆ์™ธ๋ฅผ ๋˜์ง€๊ณ ์ž ํ•  ๋•Œ๋Š”, ํ•ด๋‹น Exception class์— signal ๋ฉ”์„ธ์ง€๋ฅผ ๋˜์ง€๋ฉด ๋œ๋‹ค.

[ ^ZeroDivide signal ] on: ZeroDivide do: [ Transcript clear; show: 'Zero Divide Error !!' ]

์˜ˆ์ œ

Dice

One Dice

  • ๋ชฉํ‘œ: a ~ b ์‚ฌ์ด์˜ ์ˆซ์ž๊ฐ€ ๋žœ๋คํ•˜๊ฒŒ ๋‚˜์˜ค๋Š” ์ฃผ์‚ฌ์œ„ ๊ฐ์ฒด๋ฅผ ๊ตฌํ˜„ํ•œ๋‹ค.

Dice ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ ๋‹ค. ๋จผ์ € ๋ฒ ์ด์Šค๊ฐ€ ๋  ํด๋ž˜์Šค๊ฐ€ ํ•„์š”ํ•œ๋ฐ, Random์ด ์ ๋‹นํ•˜๊ฒ ๋‹ค.

Random subclass: #Dice
  instanceVariableNames: 'min max'
  classVariableNames: ''
  poolDictionaries: ''
  category: 'Kernel-Numbers'

์ดˆ๊ธฐํ™” ๋งค์†Œ๋“œ๋ฅผ ๋งŒ๋“ค์ž.

"Instance Method. Category: private"
setMin: minValue max: maxValue

  min := minValue.
  max := maxValue.

"Instance Method. Category: accessing"
min
  ^min

max
  ^max
"class method. Category: instance creation"
newDice: minValue to: maxValue

  | dice |

  dice := super new.
  dice setMin: minValue max: maxValue.
  dice seed: Time totalSeconds.

  ^dice.

new

  ^self newDice: 1 to: 6

์‹ค์ œ๋กœ ์ฃผ์‚ฌ์œ„๋ฅผ ๊ตด๋ฆฌ๋Š” ๋งค์„œ๋“œ๋ฅผ ์ถ”๊ฐ€.

"Instance Method. Category: dice rolling"
roll

  ^ (self next * max) truncated + min

ํ…Œ์ŠคํŠธ.

dice := Dice new.
Transcript clear.
30 timesRepeat: [ Transcript show: dice roll; show: ', ' ].

Advanced Dice

๋” ๋‹ค์–‘ํ•œ ์ฃผ์‚ฌ์œ„์˜ ํŒจํ„ด์„ ์œ„ํ•ด Interval ๊ฐ์ฒด๋ฅผ ์ด์šฉ.

ํด๋ž˜์Šค ์ •์˜ ์ˆ˜์ •.

Random subclass: #Dice
  instanceVariableNames: 'range'
  classVariableNames: ''
  poolDictionaries: ''
  category: 'Kernel-Numbers'

๊ธฐ์กด์˜ setMin:max: ๋Œ€์‹ ์— ๋‹ค์Œ๊ณผ ๊ฐ™์ด setRange: ๋งค์†Œ๋“œ๋ฅผ ์ž‘์„ฑํ•œ๋‹ค.

setRange: anInterval

  range := anInterval

๊ธฐ์กด์˜ min, max ๋งค์†Œ๋“œ๋Š” ์ œ๊ฑฐ.

๊ธฐ์กด์˜ newDice:to: ๋Œ€์‹ ์— ๋‹ค์Œ๊ณผ ๊ฐ™์ด new: ๋งค์†Œ๋“œ๋ฅผ ์ž‘์„ฑํ•œ๋‹ค. new ๋งค์†Œ๋“œ๋„ ๊ฐ™์ด ์ˆ˜์ •ํ•œ๋‹ค.

new: anInterval

  | dice |

  dice := super new.
  dice setRange: anInterval.
  dice seed: Time totalSeconds.
  
  ^dice.

new

  ^self new: (1 to: 6)

๊ธฐ์กด์˜ roll ๋งค์†Œ๋“œ๋ฅผ ์ˆ˜์ •ํ•œ๋‹ค.

roll

  ^range at: (self nextInt: range size)

ํ…Œ์ŠคํŠธ.

dice := Dice new: (10 to: 100 by: 5).
Transcript clear.
30 timesRepeat: [ Transcript show: dice roll; show: ', ' ].

"Interval ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ Array๋กœ๋„ ๊ฐ€๋Šฅ"
dice := Dice new: #(1 2 3 10 20 30).
Transcript clear.
30 timesRepeat: [ Transcript show: dice roll; show: ', ' ].