コードバトンを無理矢理Smalltalkでフォークするというのはどうだろう
Twitter / Takashi SATO
Gauche版をベースにして、ざっくりと書いてみました。Squeak3.9 と 3.10 の開発者版で動作確認(Win Vista)しています。あとは煮るなり焼くなり、よろしくお願いします。
| path file scanner wordSpecs message | path := 'words.txt'. file := FileStream fileNamed: path. scanner := Scanner new. wordSpecs := OrderedCollection new. [ [file atEnd] whileFalse: [wordSpecs add: (scanner scanTokens: file nextLine)]. ] ensure: [file ifNotNil: [file close]]. wordSpecs := wordSpecs asArray shuffled select: [:each | each size = 4]. wordSpecs sort: [:a :b | (a fourth - a third) > (b fourth - b third)]. message := '(正解->{1} / 不正解->{2} / 終了->{3})?' format: (#('Yes' 'No' 'Cancel') collect: [:each | each translated]). [:exit | wordSpecs do: [:wordSpec | PopUpMenu inform: wordSpec first. (PopUpMenu confirm: wordSpec second, String cr, message orCancel: [exit value]) caseOf: { [true] -> [wordSpec at: 3 incrementBy: 1]. [false] -> [wordSpec at: 4 incrementBy: 1]}] ] valueWithExit. file := FileStream fileNamed: path. [ wordSpecs do: [:wordSpec | wordSpec do: [:each | file nextPutAll: each storeString] separatedBy: [file space]. file cr] ] ensure: [file ifNotNil: [file close]]
words.txt
'heap' '積み重ねた物' 0 0 'exploration' '探査、探検' 0 0 'errand' '使いっ走り' 0 0 'defect' '欠点' 0 0 'allowance' '割当量' 0 0