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 PL/I

Date:04/20/05
Author:Anonymous
URL:n/a
Comments:4
Info:n/a
Score: (2.47 in 19 votes)
/* And here is the PL/I version: */

 BOTTLES: PROC OPTIONS(MAIN);

   DCL NUM_BOT FIXED DEC(3);
   DCL PHRASE1 CHAR(100) VAR;
   DCL PHRASE2 CHAR(100) VAR;
   DCL PHRASE3 CHAR(100) VAR;

   DO NUM_BOT = 100 TO 1 BY -1;

      PHRASE1 = NUM_BOT||' Bottles of Beer on the wall,';
      PHRASE2 = NUM_BOT||' Bottles of Beer';
      PHRASE3 = 'Take one down and pass it around';
      DISPLAY(PHRASE1||PHRASE2);
      DISPLAY(PHRASE3);
   END;
   PHRASE1 = 'No more Bottles of Beer on the wall, ';
   PHRASE2 = 'No more Bottles of Beer';
   PHRASE3 = 'Go to the store and buy some more';
   DISPLAY(PHRASE1||PHRASE2);
   DISPLAY(PHRASE3);
 END BOTTLES;

Download Source | Write Comment

Alternative Versions

Comments

>>  Dave said on 07/07/05 20:38:46

Dave It's been a while since I coded PL/I but I think this will work. I'm fairly sure the display of the DEC will work fine. Anyway this is what I sent to my son whom I thought had created it...

I can't seem to line it up here but you'll get the idea.

DaveK

"
See improved code... based on years of coding where you didn't move stuff unless you HAD to. This would run 100% faster on the old machines. With today’s optimizers, the code would probably fix itself.

This was back in the days when you used 2 bytes to store the year and bits to keep track of things."



BOTTLES: PROC OPTIONS(MAIN);

DCL NUM_BOT FIXED DEC(3);
DCL PHRASE1 CHAR(29);
DCL PHRASE2 CHAR(16);
DCL PHRASE3 CHAR(40) VAR;

PHRASE1 = ' Bottles of Beer on the wall,';
PHRASE2 = ' Bottles of Beer';
PHRASE3 = 'Take one down and pass it around';

DO NUM_BOT = 100 TO 1 BY -1;
DISPLAY (NUM_BOT||PHRASE1||NUM_BOT||PHRASE2);
DISPLAY(PHRASE3);
END;

PHRASE3 = 'No more '
DISPLAY(PHRASE3||PHRASE1||PHRASE3||PHRASE2);
PHRASE3 = 'Go to the store and buy some more';
DISPLAY(PHRASE3);

END BOTTLES;





>>  JohnJay60 said on 12/11/08 20:55:58

JohnJay60 Even better is to have
PHRASE1 = "Bottles of beer"
PHRASE2 = " on the wall"
and save 15 bytes.

And why do so few of these examples properly deal with the case of "1 Bottle of beer", avoiding the plural?

What a fun site, though. I've been digging up old languages I'd forgotten about since college.

>>  ken dakin said on 11/13/09 13:37:47

ken dakin The PL/1 code in the example and the 'improved example' in the comments are BOTH inneficient.
1. the DCL's for PHRASE1/2 etc can be made a STATIC structure of two fields (avoids dynamic allocation memory of VAR and allows first 2 characters to be replaced)
2. the DCL for PHRASE3 etc can be made STATIC
2. the DCL's for PHRASE1 etc can be initialized with model phrases 'xx bottles...'
(to avoid the 3 x full length assignments in the loop)
3. To avoid all arithmetic, an array of 100 char strings '99' through to 'No' can be declared and assigned to the beginning 2 bytes of each phrase.
4. Loop can be for 100 to zero to avoid last 3 assignments. Then, only the Display phrase3 is needed after the loop

QED

>>  Jeff said on 05/28/10 21:49:08

Jeff This is a riot on a mainframe- the "DISPLAY" sends output to the CONSOLES, meaning that the operators are suddenly inundated with a ton of messages.

Well done- made me smile after building it on MVS38J on Hercules.

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: