Post Reply 
HP 48GX Indefinite Loops
04-03-2022, 01:59 AM (This post was last modified: 04-03-2022 02:16 AM by MNH.)
Post: #9
RE: HP 48GX Indefinite Loops
(03-29-2022 12:30 PM)DavidM Wrote:  I don't see a problem with just using the standard WHILE...REPEAT...END structure for something like this. The following will take a string with embedded linefeeds as input and return a list of the substrings delineated by those linefeeds. I'm sure this could be optimized more, but I just wanted to show a fairly straightforward approach.

Code:
\<<
   DEPTH 1 - \-> d            @ save current depth in d
   \<<
      WHILE                   @ check condition - position of linefeed
         DUP
         10 CHR POS
         DUP
      REPEAT                  @ execute if linefeed found:
         DUP2                 @ make a copy of string & pos
         1 SWAP OVER - SUB    @ SUB everything before the linefeed
         ROT ROT 1 + 1E8 SUB  @ SUB everything after linefeed
      END
      DROP                    @ DROP the 0 indicating no more linefeeds
      DEPTH d - \->LIST       @ result is all found substrings in a list
   \>>
\>>

Thanks for your effort! I ran your code and didn't get the expected results.

Input:

1: CSV @ .txt file (comma-separated values)

Output:

4: "248,1529945.48000...
3: 0.0000
2: '→d'
1: << WHILE DUP 10.000...

I had trouble debugging your code as evidenced by stack level one above. My second attempt at writing a solution appears below.

Program: CSV→
Checksum: # 3AFBh
Bytes: 305.0
Purpose: Remove line feed characters from a string. Store
the resulting strings in a list.

\<< 1 CF CSV DUP SIZE
10 CHR { } 1 \→ csv
size char points
position
\<<
DO csv DUP DUP
char POS DUP DUP 0

\<< 'position'
STO 2 - 1 SWAP SUB
'points' STO
position 1 + size
SUB 'csv' STO
\>>
\<< 1 SF 3
DROPN points SWAP +
\>> IFTE
UNTIL 1 FS?
END
\>>
\>>

Although the desired output has been attained, the DO...UNTIL...END
structure still repeats one more time after the test condition returns a
true (nonzero) result. I have to clean up the stack, which I shouldn't have
to do if the program worked as expected. Any thoughts?
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
HP 48GX Indefinite Loops - MNH - 03-28-2022, 01:11 AM
RE: HP 48GX Indefinite Loops - MNH - 04-02-2022, 02:15 PM
RE: HP 48GX Indefinite Loops - DavidM - 03-28-2022, 04:11 AM
RE: HP 48GX Indefinite Loops - DavidM - 03-29-2022, 12:30 PM
RE: HP 48GX Indefinite Loops - MNH - 04-03-2022 01:59 AM
RE: HP 48GX Indefinite Loops - DavidM - 04-03-2022, 10:58 AM
RE: HP 48GX Indefinite Loops - DavidM - 04-03-2022, 11:39 AM
RE: HP 48GX Indefinite Loops - MNH - 04-03-2022, 05:39 PM
RE: HP 48GX Indefinite Loops - ttw - 03-30-2022, 01:02 AM
RE: HP 48GX Indefinite Loops - MNH - 04-03-2022, 12:57 PM
RE: HP 48GX Indefinite Loops - MNH - 04-03-2022, 04:25 PM



User(s) browsing this thread: 1 Guest(s)