From: jhmeyers@miu.edu (John H Meyers)
Subject: Re: UNDO and ARRAY-LIST and LIST-ARRAY
Date: 11 Jul 1997 00:00:00 GMT
Message-ID: <5q5q68$t8f$1@news.iastate.edu>
References: <199707111051.a5262@tue.maus.de>
Organization: MIU Computer Services,  Fairfield, IA 52557.  Not Approved.
Reply-To: jhmeyers@miu.edu
Newsgroups: comp.sys.hp48


In article <199707111051.a5262@tue.maus.de>,
Philip_Jackson@tue.maus.de (Philip Jackson) writes:

> Does anybody know a programme or two that converts an ARRAY into a
> LIST and the other way round?

  A collection of small conversion programs (G/GX) is re-posted below.

> The best solution would be a little programme that recognizes the
> kind of object that is in the stack and can do both operations.

  \<< { 3 5 } OVER TYPE POS { M\->L L\->M } SWAP GET EVAL \>>

  Where specific programs M\->L and L\->M are found below.

-----------------------------------

Originally posted: 16 Apr 1997
Subject: G/GX Conversion toolbox:
         {..} <==> [..] <==> [[..]] <==> { {..} {..} } etc.

Assorted small conversion programs for G/GX:

Convert between numbers, lists, vectors, and matrices;
convert between matrices and nested lists of lists;
apply any program to all elements of a list, vector, or matrix.

->L  ->V  ->M  Convert almost anything to a list, vector, or matrix.

 L->M   M->L   Convert between [[ 1 2] [3 4]] <-> { { 1 2 } { 3 4 } }

 APLL   APLY   Apply transformations to list or matrix elements (APLY
               replaces the one from TEACH/AUR, except for symbolics).

You can type any individual programs below, one at a time,
or you can download them all in a single directory below.

%%HP: T(3); @ \-> means "right-arrow" etc. (Ascii Translation mode 3)
DIR @ Start of directory, for downloading with Kermit

\->L @ number | list | vector | matrix -> list of elements
\<< DUP TYPE 1 > { OBJ\-> } 1 IFTE
    DUP SIZE 1 > { \PILIST } IFT EVAL \->LIST \>>

\->V @ number | list | vector | matrix -> vector
\<< DUP TYPE 1 > { OBJ\-> } 1 IFTE
    DUP SIZE 1 > { \PILIST } IFT \->ARRY \>>

\->M @ number | list | vector | matrix -> matrix
@ ( lists or vectors -> N x 1 matrix, having one column )
\<< DUP TYPE 1 > { OBJ\-> } 1 IFTE
    DUP SIZE 1 \<= { EVAL 1 2 \->LIST } IFT \->ARRY \>>

L\->M @ 1- or 2- dimensional list -> vector or matrix
@ { 1 2 3 } -> [ 1 2 3 ]
@ { { 1 2 } { 3 4 } } -> [[ 1 2 ]  [ 3 4 ]]
\<< 1 \<< DUP TYPE 5 == { LIST\-> \->ARRY } IFT \>> DOLIST
    OBJ\-> ROW\-> \>>

M\->L @ vector or matrix -> 1- or 2- dimensional list
@ [ 1 2 3 ] -> { 1 2 3 }
@ [[ 1 2 ]  [ 3 4 ]] -> { { 1 2 } { 3 4 } }
\<< \->ROW \->LIST
    1 \<< DUP TYPE 1 > { ARRY\-> EVAL \->LIST } IFT \>> DOLIST \>>

APLL @ Apply an object (program) to each element of nested lists
@ { 1 { 2 { 3 4 } 5 { 6 7 } 8 } }  { 1 + } -> adds 1 to each element
\<< IF OVER TYPE 5 == THEN \-> p \<<
    1 \<< p APLL \>> DOLIST \>> ELSE EVAL END \>>

APLY @ Apply an object (program) to each element of a vector or matrix
@ [[ 4 5 ] [ 6 7 ]] { 1 + } -> [[ 5 6 ] [ 7 8 ]]
\<< SWAP M\->L SWAP APLL L\->M \>>

END @ End of directory, for downloading with Kermit

-----------------------------------------------------------
With best wishes from:   John H Meyers   <jhmeyers@mum.edu>
