Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language Smalltalk

(Squeak, VisualWorks)

Date:07/03/05
Author:Jim Freeman
URL:n/a
Comments:4
Info:http://www.whysmalltalk.com/
Score: (3.97 in 212 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

VersionAuthorDateCommentsRate
OO/humor version for gstPaul H. Hargrove06/11/072
standard versionPatrick M. Ryan04/20/050

Comments

>>  Glen said on 02/23/06 17:49:38

Glen Also works in SmallTalk/X, a quite nice FREE Smalltalk bundle.

>>  Jorge said on 09/16/08 19:07:01

Jorge Works in VisualAge Smalltalk as well (version 7, Instantiations), without any modifications!

>>  Per Wigren said on 09/18/08 15:13:17

Per Wigren Tested it with GNU Smalltalk v3.0.2 and it works there also!

>>  John said on 08/17/09 12:21:52

John Works under Pharo 1.0 beta!

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!

Name:

eMail:

URL:

Security Code:
  
Comment: