Squeak はオープン ソース環境であるため、次のようなデータ構造の実装を見ることができますOrderedCollection>>addFirst
。
addFirst: newObject
"Add newObject to the beginning of the receiver. Answer newObject."
firstIndex = 1 ifTrue: [self makeRoomAtFirst].
firstIndex := firstIndex - 1.
array at: firstIndex put: newObject.
^ newObject
とOrderedCollection>>removeFirst
:
removeFirst: n
"Remove first n object into an array"
| list |
list := Array new: n.
1 to: n do: [:i |
list at: i put: self removeFirst].
^ list
その後、スタック データ構造を操作できますね。
私は、Smalltalk にはポインター構造がないことを知らされました。Java のような言語にもポインター構造はありませんが、スクリプト言語としてではなく、ツリー、ダイアグラムなどの基本的なデータ構造を実装する必要があります (「スクリプト: 21 世紀の高水準プログラミング」で参照)。
Smalltalk はどのようにツリー データ構造を実装しますか?