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 PostScript

(printable PS - also GhostScript possible)

Date:04/25/06
Author:Volker Beyler
URL:http://www.beyler.name
Comments:3
Info:http://en.wikipedia.org/wiki/PostScript
Score: (3.00 in 23 votes)
%!
% 99 Bottles Of Beer On The Wall...
% prints out the complete song on any postscript-able device,
% as well as in GhostScript etc.

/Helvetica findfont   % choose a font, I prefer Helvetica
6 scalefont           % scale font to 6 pt, one page is enough...
setfont

/str 3 string def
/bottles 99 def

99 -1 0
{
   99 bottles 8 mul 20 add moveto
   
   bottles 0 gt
      {
         bottles str cvs show
         bottles 1 gt 
            {( bottles of beer on the wall, ) show}
            {( bottle of beer on the wall, ) show}
         ifelse
         bottles str cvs show
         bottles 1 gt 
            {( bottles of beer. ) show}
            {( bottle of beer. ) show}
         ifelse
         (Take one down and pass it around, ) show
         /bottles bottles 1 sub def
      }
      {
         (No more bottles of beer on the wall, no more bottles of beer. ) show
         (Go to the store and buy some more, ) show
         /bottles bottles 99 add def   
         % "/bottles 99 def" would be sufficient,
         % but I wanted to "buy" some beer...
      }
   ifelse
   bottles 0 gt
      {
         bottles str cvs show
         bottles 1 gt 
            {( bottles of beer on the wall.) show}
            {( bottle of beer on the wall.) show}
         ifelse
      }
      {
         (no more bottles of beer on the wall.) show
      }
   ifelse
}
for

showpage

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
Postscript with graphicsMark Conger04/02/120
demonstrates more language featuresTadziu Hoffmann08/30/080

Comments

>>  Ville Saalo said on 04/27/06 11:32:34

Ville Saalo This appears to assume an A4 sheet. It doesn't fit in a letter sized page. Otherwise it works great!

>>  Volker Beyler said on 08/08/06 10:23:05

Volker Beyler Hi Ville,

this is correct. As A4 sheets are common in my place, I used those.
If you exchange the line
99 bottles 8 mul 20 add moveto
with the line
99 bottles 7 mul 20 add moveto
it works fine on letter format, too.

Thanks for the feedback!

>>   said on 04/08/08 13:42:56

I like your comment on "buying" the beer instead of defining it. Good style.

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: