GoST continue
今日のgoruby → [ruby] Log of /trunk/golf_prelude.rb
マジで開発しているらしい。こうなったら出来る範囲で追いかけることにする。
!Object methodsFor: 'golf'! doesNotUnderstand: m | a s | a := m arguments size. s := m selector, '*' copyReplaceAll: ':' with: '*:'. ^m selector: (self class allSelectors asSortedCollection detect: [ :x | (x occurrencesOf: $:) = a and: [ s match: x ] ]); sendTo: self! h ^'Hello, world!' displayNl! h: args ^('%1ello, %2orld%3' bindWithArguments: args) displayNl! q ^(thisContext sender method methodSourceString, '!') displayNl! p ^self displayNl! !CharacterArray methodsFor: 'golf'! c | s | s := self, '*'. Smalltalk keysAndValuesDo: [ :k :v | (s match: k) and: [ ^v ] ]. ^nil! !Number methodsFor: 'golf'! ~ n ^self to: n! ** n ^self raisedTo: n! doesNotUnderstand: m ^m sendTo: (1 to: self)! ! !
- 「'hoge' say」だと語順がおかしいのでObject>>#pをxtalから拝借
- cはclass/constantのc
EnumなIntはどうしようも無いので,単にIntervalへのショートカットを用意- Number>>#doesNotUnderstandで解決(追記参照)
- おまけで**
実行例:
- int_enum.gst
1~5 do:[:x|(x**2)p]!
- q.gst
{}q!
- c_p.gst
#Or c p!
$ gst GoST.st int_enum.gst q.gst c_p.gst 1 4 9 16 25 {}q! OrderedCollection
追記:
- int_enum2.st
(9se:[:x|x\\2>0])p!
$ gst GoST.st int_enum2.st (1 3 5 7 9 )