Post Reply 
hp 28s - creating nested lists
02-20-2015, 07:06 AM
Post: #21
RE: hp 28s - creating nested lists
? 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

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
02-20-2015, 12:59 PM (This post was last modified: 02-20-2015 01:25 PM by mbrethen.)
Post: #22
RE: hp 28s - creating nested lists
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.
Find all posts by this user
Quote this message in a reply
02-20-2015, 02:15 PM
Post: #23
RE: hp 28s - creating nested lists
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

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
02-20-2015, 07:00 PM (This post was last modified: 02-21-2015 06:20 AM by mbrethen.)
Post: #24
RE: hp 28s - creating nested lists
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
  \>>
\>>
Find all posts by this user
Quote this message in a reply
02-21-2015, 11:30 AM
Post: #25
RE: hp 28s - creating nested lists
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

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
Post Reply 




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