Skip to content

Instantly share code, notes, and snippets.

@ympbyc
Created October 12, 2012 14:12
Show Gist options
  • Select an option

  • Save ympbyc/3879365 to your computer and use it in GitHub Desktop.

Select an option

Save ympbyc/3879365 to your computer and use it in GitHub Desktop.
smalltalk 72 メモ. まだ実際に触ってないから想像含む。OSX Lionでたまたま使えたグリフを使ってるので見れない人はごめんなさい。
"=>はif。ほんとは⇒"
cond => (then) else

"<oはアイボールって言って続くトークンを読む.ほんとは専用のグリフがある。"
<o someToken

"☞はlispのquoteみたいなやつ。続く式を評価しない。"

"変数への代入は←。←は普通のメッセージなので変数はクオートしてやらないといけない"
☞x ← 1


"式の実行(DoIt)は!"
3 + 4!

to myclass 一時変数1 ... | インスタンス変数1 ... | クラス変数1 ... (... isnew => ...)
"でクラスmyclassを作る。変数のとこは省略できてto x temp | inst (...とかできる。
クラス名は大文字で始まるみたいなルールはなし。
コード中でmyclassが現れたらその場でインスタンスが作られる。SELFで自分自身を参照できるっぽい。"

"isnewなしだとクラスにはならず関数オブジェクトみたいにつかえるっぽい"
to square n (☞n ← :. ⇧n * n)
square 3!

"引数を受け取るには:。"
"⇧はreturn.メソッドの中で使う。"
(☞n ← :. ⇧n + 1)

これらを使うとクラスが定義できる。クラス定義

to fruit | color weight | (
  isnew => (☞color ← 'yellow')
  <o color  => (<o is => (☞color ← :)  ⇧color) "isが続いてたらsetter違ったらgetterみたいなことできる"
  <o weight => (<o is => (☞weight ← :) ⇧weight)
  <o print  => ('This fruit is ' , color , ' and weighs ' , weight , 'kg.' print) "文字列結合は想像"
)!

☞apple ← fruit!
apple color is 'red'!
apple color! "結果:red"
apple weight is 0.3!
apple print! "結果:This fruit is red and weighs 0.3kg."

クラス定義自体が巨大なif ... then else if ... then else if ...になってる。インスタンス生成時には擬変数isnewがtrueになるからこれがコンストラクタになる。

アイボール(<o)がいくらでもネストできるってことは実行時にパーサーを書いてるようなもので、実際receiver-dependent message parsingって呼ばれてる。実行の遅さと、レシーバーが違うとメッセージの書き方も全く違っちゃう(モジュラリティが低い)からSmalltalk-76でこれは捨てられた。

クラス名が現れたタイミングでインスタンスが作られるから、クラスは普通のオブジェクトとしては扱えなかった。

参考:
http://d.hatena.ne.jp/sumim/20060121/p1
http://www.languagegame.org:8080/propella/74 http://www.textfiles.com/bitsavers/pdf/xerox/alto/Smalltalk72_Manual.pdf http://stephane.ducasse.free.fr/FreeBooks/BitsOfHistory/BitsOfHistory.pdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment