Path: republic.btigate.com!news-xfer.netaxs.com!news1.chicago.iagnet.net!iagnet.net!vixen.cso.uiuc.edu!newsrelay.iastate.edu!news.iastate.edu!vax1.miu.edu!JHMEYERS
From: jhmeyers@miu.edu (John H Meyers)
Newsgroups: comp.sys.hp48
Subject: Strings.... and other object conversions
Date: 30 Dec 1997 00:00:00 GMT
Organization: MIU Computer Services,  Fairfield, IA 52557.  Not Approved.
Message-ID: <68boqg$qbu$1@news.iastate.edu>
References: <34A9363F.41A@hotmail.com>
Reply-To: jhmeyers@miu.edu
NNTP-Posting-Host: vax1.mum.edu


In article <34A9363F.41A@hotmail.com>,
Emperor Julius Caesar <jc_isd@hotmail.com> writes:

> Hi I would like to know if there is a special RPL command to convert a
> 'STRING' (with '') to "STRING" (with "" and without '');
> I had a solution not very beautiful, it's 'STRING' "" +

  That's the shortest User-RPL solution, and avoids crashes which can
  occur from wrong arguments to SYSEVAL functions -- what's wrong with it?

  To convert "name" back to 'name' you can use "'" SWAP + OBJ->
  (requires a valid global or local name, unlike the SYSEVAL function).

However, as long as we're converting things, here's a program which
"bundles" quite a few conversions into one program:

%%HP: T(3); @ "at" symbols introduce comments
@ Program CT - change object type (common conversions) [S/SX/G/GX]
\<< {
   { { 8 9 13 } OVER TYPE POS @ program, algebraic, or unit object
     { #54AFh SYSEVAL #5459h SYSEVAL } IFT } @ ->list
   6 { "" + } @ name -> string
   2 { #5B15h SYSEVAL } @ string -> name
   5 { #54AFh SYSEVAL #5445h SYSEVAL } @ list -> program
   0 { #18CEAh SYSEVAL } @ real -> bint
  20 { #18DBFh SYSEVAL } @ bint -> real
  10 { B\->R CT } @ binary -> real -> bint (recursive call)
} DUP2 SWAP TYPE POS 1 + GET EVAL \>> @ Dispatch on arg type
@ 260.5 bytes (on stack), Checksum #5C2h [verify it!]

"Bints" are 20-bit internal binary integers, commonly used as arguments
to internal system functions, e.g. 33 CT ==> <21h>.

Programs can be converted to lists; then the objects in the list can
be re-arranged and converted back into a program.  Note that the
\<< and \>> objects you see within programs are actually commands
within the program object, and that program objects themselves
are actually displayed without visible delimiters of their own.

Programs contained within other programs are often preceded by
an "invisible" quoting command (xSILENT') which will occupy
its own separate stack level if the list is separated into
its components using OBJ->.  This quoting command is what makes
programs encountered within other User-RPL programs simply
be put on the stack, rather than be executed immediately,
whereas the latter is actually the default internal behavior.

Unit objects will appear to contain some empty lists when broken up
into their components; these lists are actually in ROM, while the
unique addresses of several different ROM locations are what is
contained within the unit object itself, which cause these address
pointers to be interpreted as unit multiplication, unit division,
unit exponentiation, etc.  The string objects within unit objects
are the unit names; the "character" objects are unit prefixes
(e.g. the 'c' in 1_cm, where "m" is the unit name).

Programs and lists converted into each other by the above program
will be exactly the same length and produce exactly the same results
when evaluated in either form; unit objects can not be evaluated
when converted into lists, however.

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