Language Smalltalk
(Squeak, VisualWorks)
Date: | 07/03/05 |
Author: | Jim Freeman |
URL: | n/a |
Comments: | 4 |
Info: | http://www.whysmalltalk.com/ |
Score: | (4.00 in 210 votes) |
"Copy into a workspace, highlight the code and choose do it." "Tested under Squeak 3.7 and VisualWorks 7.3" | verseBlock | verseBlock := [ :bottles | | verse | verse := WriteStream with: (String new). bottles = 0 ifTrue: [verse nextPutAll: 'No more bottles of beer on the wall. No more bottles of beer...'; cr; nextPutAll: 'Go to the store and buy some more... 99 bottles of beer.'; cr]. bottles = 1 ifTrue: [verse nextPutAll: '1 bottle of beer on the wall. 1 bottle of beer...'; cr; nextPutAll: 'Take one down and pass it around, no more bottles of beer on the wall'; cr]. bottles > 1 ifTrue: [verse nextPutAll: bottles printString; nextPutAll: ' bottles of beer on the wall. '; nextPutAll: bottles printString; nextPutAll: ' bottles of beer...'; cr; nextPutAll: 'Take one down and pass it around, '; nextPutAll: (bottles - 1) printString, ' bottle'; nextPutAll: (((bottles - 1) > 1) ifTrue: ['s '] ifFalse: [' ']); nextPutAll: 'of beer on the wall'; cr]. verse contents]. 99 to: 0 by: -1 do: [: i | Transcript show: (verseBlock value: i); cr].
Download Source | Write Comment
Alternative Versions
Version | Author | Date | Comments | Rate |
---|---|---|---|---|
OO/humor version for gst | Paul H. Hargrove | 06/11/07 | 2 | |
standard version | Patrick M. Ryan | 04/20/05 | 0 |
Download Source | Write Comment
Add Comment
Please provide a value for the fields Name,
Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.
Please don't post large portions of code here! Use the form to submit new examples or updates instead!
Comments
Glen said on 02/23/06 17:49:38
Also works in SmallTalk/X, a quite nice FREE Smalltalk bundle.
Jorge said on 09/16/08 19:07:01
Works in VisualAge Smalltalk as well (version 7, Instantiations), without any modifications!
Per Wigren said on 09/18/08 15:13:17
Tested it with GNU Smalltalk v3.0.2 and it works there also!
John said on 08/17/09 12:21:52
Works under Pharo 1.0 beta!