HP Forums
hp 28s - creating nested lists - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: General Forum (/forum-4.html)
+--- Thread: hp 28s - creating nested lists (/thread-3116.html)

Pages: 1 2


RE: hp 28s - creating nested lists - Werner - 02-20-2015 07:06 AM

? It works for me.
When you say the code has errors, does it not compile or does it not run?
Does the 28 have a FOR .. STEP statement? If not, then you can't use this version and will have to stick to one of the two others.
(I don't have a 28)
If it compiles, then you must've entered a typo..

NDUPN is a useful little subprogram.. I always try to make 'beautiful' code, ie. short yet clear, and this way it's both ;-) And perhaps NDUPN can be used elsewhere?

Cheers, Werner


RE: hp 28s - creating nested lists - mbrethen - 02-20-2015 12:59 PM

It compiles, but as written it gives an error message about a bad 'FOR statement.' I checked for typos.

The reference manual shows the HP 28 FOR/STEP statement as:

start finish FOR name loop-clause increment STEP

increment must be a real number.

For example:
Code:
1 11 FOR x x SQ 2 STEP
places the squares of the integers 1, 3, 5, 7, 9, and 11 on the stack.


RE: hp 28s - creating nested lists - Werner - 02-20-2015 02:15 PM

Aha.. that's probably it.
The 48/49 STEP syntax specifies:
Quote:If the argument of STEP is an algebraic expression or a name, it is automatically evaluated to a number.
But the 28 accepts only a real number, not a variable holding one.
So, just add EVAL before STEP (or even better, before DUP). That should do it.
Code:
\<<
  \-> n
  \<<
    1 2 n
    FOR i
      DUPN i EVAL DUP
    STEP
    n - DUP 0 <
    { NEG DUPN }
    { DROPN }
    IFTE
    n
  \>>
\>>

Cheers, Werner


RE: hp 28s - creating nested lists - mbrethen - 02-20-2015 07:00 PM

Edit: The True/False objects in the IFTE statement should be program objects on the 28.
Code:
\<<
  \-> n
  \<<
    1 2 n
    FOR i
      DUPN i EVAL DUP
    STEP
    n - DUP 0 <
    \<< NEG DUPN \>>
    \<< DROPN \>>
    IFTE
    n
  \>>
\>>



RE: hp 28s - creating nested lists - Werner - 02-21-2015 11:30 AM

Then you might as well write it as a normal IF THEN ELSE statement

Code:
IF DUP 0 <
THEN NEG DUPN
ELSE DROPN
END

7.5 bytes shorter