まずはアドレスを公開.
http://tomoyo.mine.nu/~apple/squeak/
プログラミング初心者,大学生院生Ringo(りんご)のプログラミング言語メモ.Squeakerを目指しています
while や for がスコープを作らないのに対し、loop や each などのイテレータはスコープを作ります
(1..5).each do |i|
var = true
end
p var
$ ruby test.rb
test.rb:4: undefined local variable or method `var' for main:Object (NameError)
(1 to: 5) do:[:v |
| var |
var = true.].
var " popupが表示され,var appears to be undefined at this point. Proceed anyway"
fact := [ :n | n = 0 ifTrue: [ 1 ] ifFalse: [ n * ((fact copy fixTemps) value: n - 1) ] ].
fact copy fixTemps value: 10.
#define M_PI 3.14159265358979323846264338327950288
Float pi ==> 3.141592653589793
Float pi ==> 3.14159
Double pi ==>3.1415926535898d
Collection subclass: #OrderedDictionary
instanceVariableNames: 'keys content'
classVariableNames: ''
poolDictionaries: ''
category: 'Ringo-Collection'
OrderedDictionary methodsFor: 'enumerating'
do: aBlock
keys do:[:v | aBlock value:v].
OrderedDictionary methodsFor: 'initialize-release'
initialize
keys := OrderedCollection new.
content := Dictionary new.
OrderedDictionary methodsFor: 'accessing'
at: key
^ content at: key! !
OrderedDictionary methodsFor: 'accessing'
at: key put: value
content at: key put: value.
(keys includes:key) ifFalse:[
keys add: key.
].
^ value.
OrderedDictionary methodsFor: 'accessing'
keys
^ keys
OrderedDictionary methodsFor: 'accessing'
values
| out |
out := WriteStream on: (Array new: keys size).
keys do:[:v |
out nextPut: (content at:v)].
^ out contents
OrderedDictionary methodsFor: 'accessing'
removeKey: key
keys remove: key.
content removeKey: key.
x := OrderedDictionary new.
x
x at:#one put:1.
x at:#two put:2.
x values
x do:[:v | Transcript cr;show:v].
==>one
==>two
x removeKey:#one.
x removeKey:#two.
x ==> an OrderedDictionary()
Object subclass: #OrderedDictionary
instanceVariableNames: 'keys content'
classVariableNames: ''
poolDictionaries: ''
category: 'Ringo-Collection'
OrderedDictionary methodsFor: 'enumerating'
do: aBlock
keys do:[:v | aBlock value:v].
OrderedDictionary methodsFor: 'initialize-release'
initialize
keys := OrderedCollection new.
content := Dictionary new.
OrderedDictionary methodsFor: 'accessing'
at: key
^ content at: key! !
OrderedDictionary methodsFor: 'accessing'
at: key put: value
content at: key put: value.
(keys includes:key) ifFalse:[
keys add: key.
].
^ value.
OrderedDictionary methodsFor: 'accessing'
keys
^ keys
OrderedDictionary methodsFor: 'accessing'
values
| out |
out := WriteStream on: (Array new: keys size).
keys do:[:v |
out nextPut: (content at:v)].
^ out contents
x := OrderedDictionary new.
x
x at:#one put:1.
x at:#two put:2.
x values
x do:[:v | Transcript cr;show:v].
==>one
==>two
svn co http://squeakvm.org/svn/squeak/trunk squeak-svn
x := Matrix rows:2 columns:2.
x atColumn:1 put:#(1 2).
x atColumn:2 put:#(3 4).
x ==> a Matrix(1 3 2 4)
x := x + x. ==> a Matrix(2 6 4 8)
>> 'test'*2
=> "testtest"
s:='test'.
x := WriteStream on:''.
2 timesRepeat:[x nextPutAll:s].
x contents. 'testtest'
各クラスは通常2つのプール——Smalltalk辞書と、クラス変数が在るプール を持ち、さらに セレクタ poolDictionaries: で指定したプールを オプショナルで持つことが出来る
Smalltalk at:#Smalltalk "print it =>" a SystemDictionary(lots of globals)
クラス変数があるプールを持つ
Trait named: #Atok
uses: {}
category: 'Study-Traits'
Atok>>change
^ '日本語変換が得意です'
Object subclass: #KanjiTalk
KanjiTalk>>henkan
^ '日本語変換は苦手かもしれません'
----
KanjiTalk subclass: #Kotoeri
uses: Atok
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Study-Traits'
KanjiTalk>>conversion
^ '日本語変換はまぁまぁです'
x := Kotoeri new.
x henkan. '日本語変換は苦手かもしれません'
x conversion. '日本語変換はまぁまぁです'
x change. '日本語変換が得意です'
Object>>りんご
りんご (class)>>身長
^"146cm"
りんご 身長 "146cm"