;; 99 bottles of beer example -- simple, no cuteness. ;; Demonstrates several features of Moose, such as: cloning objects, blocks, ;; object mutability, ranges, regular expressions, etc. BottleSong -> Object clone. BottleSong current -> MutableString clone. BottleSong phraseForBottle(Number) -> [|n| cond((n = 0) ["no more bottles of beer"], (n = 1) ["1 bottle of beer"], true ["#{n} bottles of beer"])]. BottleSong doSong -> [ 99 to(1) each([i, "#{current} on the wall, #{current}." println. "take one down, pass it around, " print. current := phraseForBottle(i - 1). "#{current} on the wall" println])]. ; this isn't required, but it demonstrates how to set particular slots ; immutable ("final" in java/c# (except immutable slots can still be accessed ; through the lookup graph)) all in one go. BottleSong slots select([|s| Regex clone setPattern("(phraseForBottle|doSong)") match(s)]) each([|i| BottleSong setFlagOn('i, ObjectFlags immutableFlag)]). ; we don't need to clone this, but it's good style. song -> BottleSong clone. song doSong.