- THE PL/I NEWSLETTER - |
| - THE PL/I NEWSLETTER - |
- THE PL/I NEWSLETTER - |
In the last issue of "The PL/I Connection" I presented a PL/I problem and promised to give a solution in the next issue. That was in December 1997. I'm glad to have the opportunity to keep this promise in "The PL/I Newsletter" now.
If you remember the problem: Write a subroutine which computes the ratings of the game Master Mind. An additional requirement was, do it in eight statements or less.
For those of you who missed the original article and first want to
find a solution themselves, here is the URL:
http://www.ibm.com/software/ad/pli/pli1297.htm
I reviewed the postings of 1998 in the newsgroup "comp.lang.pl1" and
here is my favourite solution posted by Clement McGann (please,
excuse my editorial changes):
The number of white pins is the sum of all places where the hidden pins and the guessed pins are equal. (Comparison of two arrays yield a bit array which is converted to binary for the purpose of computing the sum. I may be biased but I like this statement!)
Then for each color it is checked how many times the color occurs in the hidden and in the guessed code. (Again comparing a scalar to an array yields a bit array. You can read "sum(I = Hidden)" as: Sum up all places where I is equal to a value of the array Hidden.) In Master Mind only relevant is the minimum of the two values. If you add these numbers you get the number of both black and white pins. So you have to subtract the number of white pins in order to know the number of black pins.
This Month's Problem
The problem of today uses some new features of the Visual Age PL/I
compiler. Given an ordinal variable T which can assume two values T1
and T2, I want a function also named T which returns the ordinal
value when the binary value is passed to it:
If you have a running solution you can check if you have presumed big endian or little endian representation, respectively :-)
I hope this problem is a challenge to you. Have fun, and, perhaps, learn something new. Afterwards you can decide yourself if your product is programmed in "good" or "bad" style.
You may post solutions to comp.lang.pl1, or if you prefer a more private venue, mail your solution direct to Eberhard at sturm@uni-muenster.de
Can someone among you please tell me if it's possible to do something like the following:
Reply
You do it the same way you would in "Petzold" (C / C++). But you can cut
down on the OS APIs by using FETCH
Compile all of the functions into an external DLL, and export them. The
caller can use FETCH with the TITLE option to name the DLL and the entry to
be invoked.
The same technique also allows you to have plug-in lower level code - here's
a sample from the Cogent/SQL (=> tag line) code
Regards, Mark Yudkin, Yudkin Consulting AG, Authors of Cogent/SQL for MVS,
OS/2 and Windows NT.
The PL/I
Connection
newsletter.
The PL/I Connection Newsletter No. 11 , December 1997.
The PL/I Connection Newsletter No. 10 , April 1997.
From: "Mark Yudkin"
New Update for VisualAge PL/I.
An update for VisualAge PL/I for Windows NT and Windows 2000
was scheduled for 29th September 2000.
Salient features include:
ONWCHAR, ONWSOURCE, WCHAR, WCHARVAL, WHIGH, WIDECHAR, WLOW.
Other built-in functions include:
ACOSF, ASINF, ATANF, COSF, EXPF, LOG10F, LOGF, SINF, TANF, and
CHARVAL, ISIGNED, IUNSIGNED.
Buy PL/I on the web
You may buy PL/I for OS/390, or for OS/2 and Windows NT (also the
personal edition), or PL/I Set for AIX online.
Go to
IBM's online shop.
Usefulle Webbe Lynx ...
The spring 2000 edition of the
COBOL and PL/I newsletter
has some topics about PL/I. The specific PL/I
topics may be viewed separately, or the entire newsletter in PDF
format may be downloaded.
Of particular interest is the use of PL/I as a programming
language for the Common Gateway Interface (CGI).