Post Reply 
Accessing data in linked array on HP-50g
06-27-2021, 05:19 PM (This post was last modified: 01-03-2022 10:30 PM by Giuseppe Donnini.)
Post: #5
RE: Accessing data in linked array on HP-50g
[ WARNING: The following information relates to the HP-48; it may also apply to the HP-50G, but no warranty is given. ]

Here are a few things you should keep in mind:
  • At the User RPL level, linked arrays are treated as system objects, which are not meant to be handled directly by the user. They are therefore simply decompiled as Linked Array – regardless of their actual contents.
  • The same holds true for ordinary arrays that do not conform to the specific requirements of a User RPL array, which must either be a vector (or one-dimensional array) of real or complex numbers, or a matrix (or two-dimensional array) of real or complex numbers. Anything else is simply decompiled – at least on the HP-48 – as Array of <object type>. How does your program handle such non-standard arrays? Did you make provisions for arrays of any type and dimensionality?
  • It is not possible to convert a linked array to an unlinked one without addressing the null-pointer problem. How should inexistent elements be represented in an ordinary array? You could use default values, but they are not guaranteed to be distinguishable from actual values, since both must be of the same type.
  • It is a bit easier to convert a linked array to a list because the latter is a composite object and can therefore hold a pointer to a unique placeholder value, like NOVAL, in order to represent a void element. (Note, however, that NOVAL is not available on the HP-48S/SX.).

The following program, which I tentatively call LA\->, takes a linked array as argument and returns its elements in row order to the stack, followed by a list specifying its dimensions. Non-existent elements are represented by the special placeholder NOVAL. For this reason, the program will not run on an HP-48S/SX.

* LA\->                                                           G/G+/GX only
* ABSTRACT : Dissects a linked array by returning its elements in row order,
*            followed by a list of its dimensions.
* STACK    : ( lnkarry --> el1...eln { %dim1...%dimx } )
*            * Non-existent elements are represented by xNOVAL.
*            * The dimension(s) are always returned in a list, even when the
*              initial argument is a vector, that is, a one-dimensional linked
*              array.

* Binary transfer header.

        NIBASC /HPHP48-K/

* Unsupported, but stable entry points:

=lnkarry      EQU #1CCD8

* Rompointer entry points:

=~xNOVAL      EQU #05B0AB



  CK1NoBlame         ( *Require 1 argument without recording the command* )
  CK&DISPATCH1       ( *Dispatch table including second, tag-stripping, pass* )
  lnkarry            ( *Require linked array, or tagged linked array* )
  ::                 ( lnkarry --> )
    ARRYLP_DO (DO)   ( *Take apart linked array* )
      INDEX@ OVER    ( el1...eli-1 lnkarry #i lnkarry )
      GETATELN       ( el1...eli-1 lnkarry <eli TRUE>|<FALSE> )
      ?SKIP          ( *If element does not exist,... )
      xNOVAL         (  ...return xNOVAL instead* )
      SWAP           ( el1...eli-1 eli lnkarry )
    LOOP             ( el1...eln lnkarry )
    DIMLIMITS        ( el1...eln { #dim1...#dimx } )
    INNERCOMP        ( *Convert bints to reals within dimension list* )
    ZERO_DO (DO)
    LOOP             ( --> el1...eln { %dim1...%dimx } )

N.B. The second loop could be optimized by return stack manipulations, but since the chances of encountering a zillionth-dimensional array are reasonably low, I opted for the most legible form.

A compiled version of the program, called LAto, is attached to the posting, together with three already compiled linked arrays for testing purposes:
  • LA1 is a copy of the only linked array present in the ROM of the HP-48G/G+/GX. It is a vector of 119 character strings and constitutes the message table for the Plot Input Form.
  • LA2 is a four-element vector of real numbers of which only the second (% 2) is present.
  • LA3 is a three-dimensional 2 x 3 x 4 array of 24 system binary integers, half of which (the odd numbers) are present.

Attached File(s)
.zip (Size: 2.28 KB / Downloads: 7)
Find all posts by this user
Quote this message in a reply
Post Reply 

Messages In This Thread
RE: Accessing data in linked array on HP-50g - Giuseppe Donnini - 06-27-2021 05:19 PM

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