• counting upper and lowercase characters

    From Bruce Axtens@21:1/5 to All on Fri Nov 18 22:37:19 2022
    Given this working version

    IDENTIFICATION DIVISION.
    PROGRAM-ID. HELLO-WORLD.
    DATA DIVISION.
    WORKING-STORAGE SECTION.
    01 UC-COUNTER PIC 99.
    01 LC-COUNTER PIC 99.
    PROCEDURE DIVISION.
    INSPECT "My dog has fleas"
    TALLYING UC-COUNTER FOR ALL 'A','B','C','D','E','F',
    'G','H','I','J','K','L','M','N','O','P','Q','R','S','T',
    'U','V','W','X','Y','Z'
    LC-COUNTER FOR ALL 'a','b','c','d','e','f',
    'g','h','i','j','k','l','m','n','o','p','q','r','s','t',
    'u','v','w','x','y','z'.
    DISPLAY UC-COUNTER " UPPER CASE CHARACTERS".
    DISPLAY LC-COUNTER " LOWER CASE CHARACTERS".

    GOBACK.
    ```
    Is there a better way of expressing the alphabets? That is, can we have a SPECIAL-NAMES or something like that so that the instruction can be INSPECT TALLYING FOR ALL LATIN-UPPERCASE-LETTERS-ENGLISH or something similar?

    -- Bruce

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Bruce Axtens@21:1/5 to All on Sat Nov 19 01:56:42 2022
    IDENTIFICATION DIVISION.
    PROGRAM-ID. HELLO-WORLD.
    ENVIRONMENT DIVISION.
    CONFIGURATION SECTION.
    SPECIAL-NAMES.
    CLASS UPPER-CASE-ENGLISH-LETTERS IS
    'A','B','C','D','E','F','G','H','I','J','K','L','M',
    'N','O','P','Q','R','S','T','U','V','W','X','Y','Z'.
    DATA DIVISION.
    WORKING-STORAGE SECTION.
    01 UC-COUNTER PIC 99.
    PROCEDURE DIVISION.
    INSPECT "My dog has fleas"
    TALLYING UC-COUNTER FOR ALL UPPER-CASE-ENGLISH-LETTERS.
    DISPLAY UC-COUNTER " UPPER CASE CHARACTERS".
    STOP RUN.

    Doesn't work, of course, as INSPECT doesn't allow CLASSes to be used. Even so ...

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From docdwarf@panix.com@21:1/5 to bruce.axtens@gmail.com on Sat Nov 19 14:05:33 2022
    In article <60d51dc4-dcc6-4878-a351-487008c76db1n@googlegroups.com>,
    Bruce Axtens <bruce.axtens@gmail.com> wrote:
    IDENTIFICATION DIVISION.
    PROGRAM-ID. HELLO-WORLD.
    ENVIRONMENT DIVISION.
    CONFIGURATION SECTION.
    SPECIAL-NAMES.
    CLASS UPPER-CASE-ENGLISH-LETTERS IS
    'A','B','C','D','E','F','G','H','I','J','K','L','M',
    'N','O','P','Q','R','S','T','U','V','W','X','Y','Z'.
    DATA DIVISION.
    WORKING-STORAGE SECTION.
    01 UC-COUNTER PIC 99.
    PROCEDURE DIVISION.
    INSPECT "My dog has fleas"
    TALLYING UC-COUNTER FOR ALL UPPER-CASE-ENGLISH-LETTERS.
    DISPLAY UC-COUNTER " UPPER CASE CHARACTERS".
    STOP RUN.

    Doesn't work, of course, as INSPECT doesn't allow CLASSes to be used.
    Even so ...

    A question, Mr Axtens: is the goal of the exercise to get the count of characters or is it to get the count of characters using INSPECT?
    Consider:

    05 TEST-BED PIC X(20) VALUE SPACES.
    05 WS-TEST-AREAS.
    10 WS-TEST-ALPHA PIC X VALUE SPACES.
    88 UCASE-ALPHA VALUES 'A' THRU 'H', 'I' THRU 'R', 'S' THRU 'Z'.
    88 LCASE-ALPHA VALUES 'a' THRU 'h', 'i' thru 'r', 's' thru 'z.
    88 A-SPACE VALUE X'40'.
    88 SPECL-CHAR VALUE X'05', X'62'.


    MOVE 'My dog has fleas' TO TEST-BED.
    MOVE UKELELE-PLAYER TO ANOTHER-NEIGHBORHOOD.
    PERFORM VARYING TALLY FROM 1 BY 1 UNTIL TALLY > (LENGTH OF TEST-BED)
    MOVE TEST-BED(TALLY:1) TO WS-TEST-ALPHA
    IF UCASE-ALPHA ADD 1 TO UC-CTR
    IF LCASE-ALPHA ADD 1 TO LC-CTR

    ... and so on. First, I was taught that you have to be very careful
    coding INSPECTS because some shops wouldn't look too closely when they
    found something 'that worked'... and INSPECT (SORT, too) work really in
    batch but less so in the online regions.

    Next, this method tries to restrict hardcoding out of the PROCEDURE
    DIVISION. It all goes into WORKING-STORAGE until there's so much stuff
    that needs to be checked they redesign the code to load tables during HOUSEKEEPING.

    DD

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arnold Trembley@21:1/5 to docdwarf@panix.com on Sun Nov 20 01:56:47 2022
    On 11/19/2022 8:05 AM, docdwarf@panix.com wrote:
    In article <60d51dc4-dcc6-4878-a351-487008c76db1n@googlegroups.com>,
    Bruce Axtens <bruce.axtens@gmail.com> wrote:
    (SNIP)

    Doesn't work, of course, as INSPECT doesn't allow CLASSes to be used.
    Even so ...

    A question, Mr Axtens: is the goal of the exercise to get the count of characters or is it to get the count of characters using INSPECT?
    Consider:

    05 TEST-BED PIC X(20) VALUE SPACES.
    05 WS-TEST-AREAS.
    10 WS-TEST-ALPHA PIC X VALUE SPACES.
    88 UCASE-ALPHA VALUES 'A' THRU 'H', 'I' THRU 'R', 'S' THRU 'Z'.
    88 LCASE-ALPHA VALUES 'a' THRU 'h', 'i' thru 'r', 's' thru 'z.
    88 A-SPACE VALUE X'40'.
    88 SPECL-CHAR VALUE X'05', X'62'.


    MOVE 'My dog has fleas' TO TEST-BED.
    MOVE UKELELE-PLAYER TO ANOTHER-NEIGHBORHOOD.
    PERFORM VARYING TALLY FROM 1 BY 1 UNTIL TALLY > (LENGTH OF TEST-BED)
    MOVE TEST-BED(TALLY:1) TO WS-TEST-ALPHA
    IF UCASE-ALPHA ADD 1 TO UC-CTR
    IF LCASE-ALPHA ADD 1 TO LC-CTR

    ... and so on. First, I was taught that you have to be very careful
    coding INSPECTS because some shops wouldn't look too closely when they
    found something 'that worked'... and INSPECT (SORT, too) work really in
    batch but less so in the online regions.

    I'm pretty sure if you use this method, you could define your own CLASS
    TEST alphabets and use them. For example,

    EVALUATE TRUE
    WHEN TEST-BED (TALLY:1) IS MY-UPPER-CASE
    ADD +1 TO UC-CTR
    WHEN TEST-BED (TALLY:1) IS MY-LOWER-CASE
    ADD +1 TO LC-CTR
    END-EVALUATE

    You don't want to use the built-in ALPHABETIC-UPPER and ALPHABETIC-LOWER classes because they include SPACE as an alphabetic character, which I
    presume must be simultaneously upper-case and lower-case.

    I'm retired now, but I recall that once we got to IBM COBOL for MVS it
    became safe to use several verbs like INSPECT in online CICS programs,
    because the underlying Language Environment library routines were made re-entrant (possibly even threadsafe). You still don't want to code
    OPEN and CLOSE in a CICS program, however, for obvious reasons.


    Next, this method tries to restrict hardcoding out of the PROCEDURE
    DIVISION. It all goes into WORKING-STORAGE until there's so much stuff
    that needs to be checked they redesign the code to load tables during HOUSEKEEPING.

    DD

    We had a style rule to reduce or eliminate hardcoding literals in the
    PROCEDURE DIVISION. It was supposed to help prevent certain kinds of
    logic errors. I recall a billing program that had three instances of multiplying a transaction count by a billing rate of a half-cent. If
    the half-cent billing rate was a literal and needed to be changed to
    .006, what are the odds a maintenance programmer would change two of the literals and miss the third?

    Kind regards,



    --
    https://www.arnoldtrembley.com/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From docdwarf@panix.com@21:1/5 to arnold.trembley@att.net on Sun Nov 20 14:44:32 2022
    In article <PuKdnU2C_6MiQOT-nZ2dnZfqnPednZ2d@giganews.com>,
    Arnold Trembley <arnold.trembley@att.net> wrote:
    On 11/19/2022 8:05 AM, docdwarf@panix.com wrote:
    In article <60d51dc4-dcc6-4878-a351-487008c76db1n@googlegroups.com>,
    Bruce Axtens <bruce.axtens@gmail.com> wrote:
    (SNIP)

    Doesn't work, of course, as INSPECT doesn't allow CLASSes to be used.
    Even so ...

    A question, Mr Axtens: is the goal of the exercise to get the count of
    characters or is it to get the count of characters using INSPECT?
    Consider:

    05 TEST-BED PIC X(20) VALUE SPACES.
    05 WS-TEST-AREAS.
    10 WS-TEST-ALPHA PIC X VALUE SPACES.
    88 UCASE-ALPHA VALUES 'A' THRU 'H', 'I' THRU 'R', 'S' THRU 'Z'.
    88 LCASE-ALPHA VALUES 'a' THRU 'h', 'i' thru 'r', 's' thru 'z.
    88 A-SPACE VALUE X'40'.
    88 SPECL-CHAR VALUE X'05', X'62'.


    MOVE 'My dog has fleas' TO TEST-BED.
    MOVE UKELELE-PLAYER TO ANOTHER-NEIGHBORHOOD.
    PERFORM VARYING TALLY FROM 1 BY 1 UNTIL TALLY > (LENGTH OF TEST-BED)
    MOVE TEST-BED(TALLY:1) TO WS-TEST-ALPHA
    IF UCASE-ALPHA ADD 1 TO UC-CTR
    IF LCASE-ALPHA ADD 1 TO LC-CTR

    ... and so on. First, I was taught that you have to be very careful
    coding INSPECTS because some shops wouldn't look too closely when they
    found something 'that worked'... and INSPECT (SORT, too) work really in
    batch but less so in the online regions.

    I'm pretty sure if you use this method, you could define your own CLASS
    TEST alphabets and use them. For example,

    EVALUATE TRUE
    WHEN TEST-BED (TALLY:1) IS MY-UPPER-CASE
    ADD +1 TO UC-CTR
    WHEN TEST-BED (TALLY:1) IS MY-LOWER-CASE
    ADD +1 TO LC-CTR
    END-EVALUATE

    You don't want to use the built-in ALPHABETIC-UPPER and ALPHABETIC-LOWER >classes because they include SPACE as an alphabetic character, which I >presume must be simultaneously upper-case and lower-case.

    That's why the 88 A-SPACE is coded all on its own. Maybe it's time for me
    to stop coding it in EBCDIC, as well.

    [snip]


    Next, this method tries to restrict hardcoding out of the PROCEDURE
    DIVISION. It all goes into WORKING-STORAGE until there's so much stuff
    that needs to be checked they redesign the code to load tables during
    HOUSEKEEPING.

    We had a style rule to reduce or eliminate hardcoding literals in the >PROCEDURE DIVISION. It was supposed to help prevent certain kinds of
    logic errors. I recall a billing program that had three instances of >multiplying a transaction count by a billing rate of a half-cent. If
    the half-cent billing rate was a literal and needed to be changed to
    .006, what are the odds a maintenance programmer would change two of the >literals and miss the third?

    The same as the odds for any sort of previously-unencountered, obscure
    error during an important batch run: 100%.

    DD

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Bill Gunshannon@21:1/5 to Arnold Trembley on Sun Nov 20 10:12:17 2022
    On 11/20/22 02:56, Arnold Trembley wrote:
    On 11/19/2022 8:05 AM, docdwarf@panix.com wrote:
    In article <60d51dc4-dcc6-4878-a351-487008c76db1n@googlegroups.com>,
    Bruce Axtens  <bruce.axtens@gmail.com> wrote:
    (SNIP)

    Doesn't work, of course, as INSPECT doesn't allow CLASSes to be used.
    Even so ...

    A question, Mr Axtens: is the goal of the exercise to get the count of
    characters or is it to get the count of characters using INSPECT?
    Consider:

    05  TEST-BED PIC X(20) VALUE SPACES.
    05  WS-TEST-AREAS.
         10  WS-TEST-ALPHA PIC X VALUE SPACES.
             88  UCASE-ALPHA VALUES 'A' THRU 'H', 'I' THRU 'R', 'S' THRU 'Z'.
             88  LCASE-ALPHA VALUES 'a' THRU 'h', 'i' thru 'r', 's' thru 'z.
             88  A-SPACE VALUE X'40'.
             88  SPECL-CHAR VALUE X'05', X'62'.


    MOVE 'My dog has fleas' TO TEST-BED.
    MOVE UKELELE-PLAYER TO ANOTHER-NEIGHBORHOOD.
    PERFORM VARYING TALLY FROM 1 BY 1 UNTIL TALLY > (LENGTH OF TEST-BED)
         MOVE TEST-BED(TALLY:1) TO WS-TEST-ALPHA
             IF UCASE-ALPHA ADD 1 TO UC-CTR
             IF LCASE-ALPHA ADD 1 TO LC-CTR

    ... and so on.  First, I was taught that you have to be very careful
    coding INSPECTS because some shops wouldn't look too closely when they
    found something 'that worked'... and INSPECT (SORT, too) work really in
    batch but less so in the online regions.

    I'm pretty sure if you use this method, you could define your own CLASS
    TEST alphabets and use them.  For example,

        EVALUATE TRUE
        WHEN TEST-BED (TALLY:1) IS MY-UPPER-CASE
            ADD +1   TO UC-CTR
        WHEN TEST-BED (TALLY:1) IS MY-LOWER-CASE
            ADD +1   TO LC-CTR
        END-EVALUATE


    I never liked that EVALUATE TRUE stuff preferring something closer
    to the good old fashioned CASE statement like:

    EVALUATE TEST-BED (TALLY:1)
    WHEN "A" THRU "Z" ADD 1 TO UC-CTR
    WHEN "a" THRU "z" ADD 1 TO LC-CTR
    END-EVALUATE

    I haven't actually tried this but I see no reason it wouldn't work.

    bill

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)