【激突】関数型言語 VS オブジェクト指向言語2at TECH【激突】関数型言語 VS オブジェクト指向言語2 - 暇つぶし2ch■コピペモード□スレを通常表示□オプションモード□このスレッドのURL■項目テキスト266:デフォルトの名無しさん 12/04/13 10:10:13.95 マクロも型クラスも多値もモナドも無いけどSqueak Smalltalkで。 Trait named: #FizzBuzz uses: #() category: 'FizzBuzz-Trait' FizzBuzz >> fizzBuzzPrep self value isString ifFalse: [thisContext sender receiver: self -> '']. FizzBuzz >> fizzBuzzReturn | method nextByte type | method := thisContext sender sender method. nextByte := thisContext sender sender method at: thisContext sender sender pc. type := nextByte // 16. ^(type = 13 and: [FizzBuzz selectors includes: (method literalAt: nextByte \\ 16 + 1)]) ifTrue: [self] ifFalse: [self value ifEmpty: [self key]] FizzBuzz >> fizz self fizzBuzzPrep. (self key isDivisibleBy: 3) ifTrue: [self value: self value, 'Fizz']. ^self fizzBuzzReturn FizzBuzz >> buzz self fizzBuzzPrep. (self key isDivisibleBy: 5) ifTrue: [self value: self value, 'Buzz']. ^self fizzBuzzReturn FizzBuzz >> gizz self fizzBuzzPrep. (self key isDivisibleBy: 7) ifTrue: [self value: self value, 'Gizz']. ^self fizzBuzzReturn Integer uses: FizzBuzz. Association uses: FizzBuzz. 105 fizz gizz buzz. "=> 'FizzGizzBuzz' " 次ページ最新レス表示レスジャンプ類似スレ一覧スレッドの検索話題のニュースおまかせリストオプションしおりを挟むスレッドに書込スレッドの一覧暇つぶし2ch