Language Smalltalk
(Squeak, VisualWorks)
| Date: | 07/03/05 |
| Author: | Jim Freeman |
| URL: | n/a |
| Comments: | 4 |
| Info: | http://www.whysmalltalk.com/ |
| Score: |
"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