今日のGoST
- CodeRepos に間借り。
- 結局 Golf クラスを作ってまとめることにした。
Object subclass: #Golf instanceVariableNames: '' classVariableNames: 'Dic Global' poolDictionaries: '' category: 'Golf'! Golf.Dic := Dictionary new. Golf.Global := Dictionary new add: $< -> stdin; add: $> -> stdout; add: $* -> Smalltalk arguments; add: $S -> Smalltalk; add: $X -> thisContext; add: $/ -> Character nl; add: $\ -> nil; yourself! !Golf class methodsFor: 'golf'! printOn: s s nextPutAll: self D; nl; nextPutAll: self G! D ^'Golf', Dic displayString! G ^String streamContents: [:s| Global associationsDo: [:a| s << a; nl ] ]!
- JARP#200801091 を採用。
!SequenceableCollection methodsFor: 'golf'! displayOn: s | j | (j := Golf.Global at: $\) isNil ifTrue: [ self do: [:x| x displayOn: s ] ] ifFalse: [ self do: [:x| x displayOn: s ] separatedBy: [ j displayOn: s ] ]! !False methodsFor: 'golf'! displayOn: s! !UndefinedObject methodsFor: 'golf'! displayOn: s!
$./gost.st -Q - st> #(1$2'3')P! 123 st> $\<-$|.#(1nil $2false'3')P! 1||2||3
いい感じ。
ただ nil はともかく,false が '' になって嬉しい状況がいまいち想像できない。