Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Normalizing DOLIST & DOSUBS

49 views
Skip to first unread message

John H Meyers

unread,
May 27, 1996, 3:00:00 AM5/27/96
to

HP48G/GX functions DOLIST and DOSUBS have the following quirks
which may be irksome if you are processing variable-length lists
or doing conditional processing on items in lists:

o Empty input lists are not accepted.

o If an empty result list would be called for, the HP48G/GX
instead just fails to return any result at all.

The following functions may be substituted for DOLIST and DOSUBS
to "normalize" this behavior, i.e. to accept empty input lists
and to *always* return a result list, even if empty.

Use of these functions may save steps in other programs,
which no longer need include any "special case" tests.

These may be stored in HOME or put in a library or Port 0,
as convenient, to make them available to all other programs:

%%HP: T(3); @ set "ascii translation mode" to 3

DOLST @ Corrects DOLIST anomalies:
@ accepts empty arg list(s) ; returns result list even if empty
\<< 1 \-> x n \<< @ assumes N = 1 if not specified
IF DUP TYPE NOT THEN 0 RND 'n' STO END
IF DUP SIZE THEN DEPTH \-> d
\<< n x DOLIST DEPTH d n - \<= { { } } IFT \>>
ELSE n 1 - DROPN END \>> \>>

DOSBS @ Corrects DOSUBS anomalies:
@ accepts empty arg list ; returns result list even if empty
\<< 1 \-> x n \<< @ assumes N = 1 if not specified
IF DUP TYPE NOT THEN 0 RND 'n' STO END
DUP SIZE { DEPTH \-> d
\<< n x DOSUBS DEPTH d < { { } } IFT \>>
} IFT \>> \>>

When you *omit* the stack argument specifying the number of lists
for DOLIST (or the number of args per frame for DOSUBS), the HP48G/GX
normally analyzes your level-1 object, and either determines the
correct value if it can, or errors if it can't.

However, the above functions assume that an omitted number *always means 1*
(an assumption I prefer for my own use).

The original "hardware" assumption can be restored by:

o Changing the initial 1 to 0 in each program
o Inserting: ... n DUP NOT { DROP } IFT x DOLIST ... (or DOSUBS)
^^^^^^^^^^^^^^^^^^^^

-----------------------------------------------------------
With best wishes from: John H Meyers ( jhme...@mum.edu )

John H Meyers

unread,
May 28, 1996, 3:00:00 AM5/28/96
to

In article <4objjg$c...@news.iastate.edu>,
jhme...@miu.edu (John H Meyers) wrote:

<...everything snipped...>

Programs were provided which "normalize" DOLIST and DOSUBS
to deal properly with empty result and/or input lists.

The programs are fine, and work as indicated.

The suggestion at the very end of the article, however, about
modifying the programs, is valid only for DOSBS (the DOSUBS
alternative), and not for DOLST (the DOLIST alternative).

0 new messages