The Museum of HP Calculators

HP Forum Archive 21

[ Return to Index | Top of Index ]

RPL: STO removes tags
Message #1 Posted by Chris Randle (UK) on 13 Mar 2012, 4:40 a.m.

Why, on RPL machines, does STOing a tagged object remove the tag?

      
Re: RPL: STO removes tags
Message #2 Posted by Gilles Carpentier on 13 Mar 2012, 8:51 a.m.,
in response to message #1 by Chris Randle (UK)

I don't know why but note that the tags always disapears when you do arithmetic or others operations (stack manipulations exclude) on the tagged object ...

but if you need this you can create this 2 shorts programs in the root directory :

<< SWAP ->STR SWAP STO >> 'STOT' STO

<< RCL STR-> >> 'RCLT' STO

And use STOT and RCLT to store and recall tagged objects in place of STO and RCL

Edited: 13 Mar 2012, 9:09 a.m.

            
Re: RPL: STO removes tags
Message #3 Posted by C.Ret on 13 Mar 2012, 4:48 p.m.,
in response to message #2 by Gilles Carpentier

Bonsoir Gilles

Your idea to store object as string trigger me.

There is a simpler way to leave arguments when using STO instruction.

Suppose you are on the way to compute . But you know you will have to use very soon in further computations.

In RPN calculator, you may certainly spare typing by storing the specific value of on the fly during the calculation of phi:

Keys strokes            Calculator Display          Remarks
1 [ENTER^]               1.0000                     Start phi computation
5 [ SQRT ]               2.2361                     Specific value displayed
[ STO ] [ 0 ][ 5 ]       2.2361                     STOre specific value ‘on the fly’
[ + ]                    3.2361                     Continue computation
2 [ / ]                  1.6180                     Get final result (phi).

On RPL system, as STO consumes arguments from stack, it make the specific valu disappear. To store it ‘on the fly’, duplicate have to be made to keep it in stack: (suppose 4 FIX and ‘R05’ use as 5th register

Keys strokes            System Display            Remarks
1 [ENTER]                1.0000                     Start phi computation
5 [ SQRT ]               2.2361                     Specific value displayed
[ENTER] ‘R05’ [ STO ]    2.2361                     STOre specific value ‘on the fly’ need several more key strokes
[ + ]                    3.2361                     Continue computation
2 [ / ]                  1.6180                     Get final result (phi).

A few years ago, to use ‘store on-the-fly’ of numerical on my HP-28S, I wrote these 3 short instruction : ClRegs to clear numeric registers (all register R00 to R99 set to zero) STOR to store one numerical into a register (no extra ENTER to duplicate) RCLR to recall one numerical from a register KEY2D to get two digits from keyboard (sub-routine of both STOR and RCLR).

ClRegs: « { 100 } 0 CON ‘REGS’ STO » 

STOR: « ‘REGS’ “STO ” KEY2D 3 PICK ->NUM PUT » @ ->NUM is optional

RCLR: « ‘REGS’ “RCL ” KEY2D GET »

KEY2D: « -> Msg @ Message string used to display STO -- or RCL -- « “” DO Msg OVER “__” + 1 2 SUB + 4 DISP @ “_” is 95 CHR DO UNTIL KEY END IF DUP “BACK” == @ “BACK” is left-arrow used to restart entry THEN DROP2 “” ELSE IF DUP “0” >= OVER “9” <= AND @ “0” to “9”: only numerical entry allowed THEN + ELSE DROP @ remova any bad entry END END UNTIL DUP SIZE 2 == END @ two digit (100 register 00 to 99) Msg OVER + 4 DISP @ optinal : shortly display last key before quitting STR-> 1 + CLMF @ restore standard stack view display »

Usage : [pre] Keys strokes Calculator Display Remarks 1 [ENTER] 1.0000 Start phi computation 5 [ SQRT ] 2.2361 Specific value displayed [ STOR ] STO __ [ 0 ] STO 0_ [ 5 ] 2.2361 STOre specific value ‘on the fly’ [ + ] 3.2361 Continue computation 2 [ / ] 1.6180 Get final result (phi).

Isn’t RPL’s “store in the fly” as cool as RPN ?

                  
Re: RPL: STO removes tags
Message #4 Posted by Gilles Carpentier on 13 Mar 2012, 6:10 p.m.,
in response to message #3 by C.Ret

Salut C.Ret ;D

interesting idea ! But it's not the question of Chris

                        
Re: RPL: STO removes tags
Message #5 Posted by C.Ret on 14 Mar 2012, 5:35 a.m.,
in response to message #4 by Gilles Carpentier

Right,

As you already know it, I am old now.... :-)

            
Re: RPL: STO removes tags
Message #6 Posted by Ronald Williams on 13 Mar 2012, 8:37 p.m.,
in response to message #2 by Gilles Carpentier

Quote:
I don't know why but note that the tags always disapears when you do arithmetic or others operations (stack manipulations exclude) on the tagged object ...

but if you need this you can create this 2 shorts programs in the root directory :

<< SWAP ->STR SWAP STO >> 'STOT' STO

<< RCL STR-> >> 'RCLT' STO

And use STOT and RCLT to store and recall tagged objects in place of STO and RCL


You may want to check page 21-34 and 21-35 of the User Guide and page 3-14 of the User Manual. For mathematical operations with tagged quantities, the calculator will "detag" the quantity automatically before the operation. Although not stated I think the same "auto" "detag" operation occurs during STO operations.

      
Re: RPL: STO removes tags
Message #7 Posted by C.Ret on 13 Mar 2012, 3:27 p.m.,
in response to message #1 by Chris Randle (UK)

Hi,

In the above message Gilles give one of the reasons why STO consume arguments from the stack.

As Gilles point it out, all instructions or commands in RPL consume arguments from stack et return results to it.

Since STO have no output object to return, it is only consuming arguments from stack.

One another reason is due to the philosophy of RPL system. Despite RPN calculators where STO is only use to store a specific value into a register for further uses and where (most of the time) you need to store a specific value 'on the fly' as soon as you enter it or get it as an intermediate result during ongoing calculations.

In RPL, the main purpose of STO is to store an object in memory. Most of the time, this objet is a program or an algebraic function or expression. STO is a way to extend the capabilities of the RPL system, to add user-defined instructions or functions into the system capabilities.

So most of the time, when invoking STO, the stack contains no specific value, but a definition, i.e. an algebraic formal expression or user-RPL program. You have to store it into memory for further use and dynamic use it by invoking this new objet by its name or through a soft-key menu. This is quite a different situation, far from the use of registers to store specific numerical value. The RPL philosophy is to store definition, program etc into memory and to keep data and values into the stack. Results are put into the stack to be use on further operation as future argument for new computation.

Of course, you can store specific value into register 'on the fly' but a direct use of STO will drive you into trouble because the intermediate result disappears from stack and that will interrupt your current on-going calculation.

As suggested by Gilles, if you plan to often store specific numerical values 'on the fly' during calculations, you better have to create a more appropriate custom-STO instruction.

            
Re: RPL: STO removes tags
Message #8 Posted by Chris Randle (UK) on 13 Mar 2012, 4:22 p.m.,
in response to message #7 by C.Ret

Hi C.Ret,

Thanks for the detailed reply. A good explanation of the different mindset required when switching from RPN-style register use to RPL objects, especially when programming.

I suspect that I didn't pose my original question well as I might have done. It's not that STO consumes its arguments from the stack, it's that it alters the tagged object before STOing it. I can't think of any other object type that behaves that way. For example, if you STO this:

Length: 10_cm

and then RCL it, you get:

10_cm

If you EVAL a tagged object, it too strips the tag, but I don't think that's what's happening here, because if you EVAL '1 + 2' you get '3', but when you STO the algebraic object '1 + 2', RCL will return '1 + 2', unevaluated.

I can see some logic to removing the tag from an object involved in a further arithmetic operation, but not the simple act of STOing it for later RCL.

Edited: 13 Mar 2012, 4:56 p.m. after one or more responses were posted

                  
Re: RPL: STO removes tags
Message #9 Posted by C.Ret on 13 Mar 2012, 4:52 p.m.,
in response to message #8 by Chris Randle (UK)

Ah! Sorry for missinterpreting your question.

I am afraid of being of no great help, since I have few expertise on "new RPL". No tag are present on my HP-28S.

It looks like the Tag is attached to the stack level, not the object !

Edited: 13 Mar 2012, 4:53 p.m.

                  
Re: RPL: STO removes tags
Message #10 Posted by Gilles Carpentier on 13 Mar 2012, 5:54 p.m.,
in response to message #8 by Chris Randle (UK)

"I can see some logic to removing the tag from an object involved in a further arithmetic operation, but not the simple act of STOing it for later RCL. "

I agree with you. It's a curious behavior. Perhaps just an HP choice to avoid some internal complexity but i don't see why it could be complex. An object on the stack should be storable "as it is" in a variable.

I just note that a tagged object is type 12 ( Height:180.), a unit is type 13 (180._cm). And type 12 or 13 embeds another 'object type' (0 for a real number). A 'tagged unit' object ( Height:180._cm) is type 12 (and not 13) , and you must do OBJ-> twice to access to the 'final' object (180.). But this works on the stack, so why not in a var ?

Seems that 'tagged objects' were just in the mind of RPL conceptors to facilitate the reading of the stack in an interactive way and precisely to clarify the outputs of programs

Edited: 13 Mar 2012, 6:30 p.m.

                  
Re: RPL: STO removes tags
Message #11 Posted by Didier Lachieze on 14 Mar 2012, 8:31 a.m.,
in response to message #8 by Chris Randle (UK)

Quote:
Seems that 'tagged objects' were just in the mind of RPL conceptors to facilitate the reading of the stack in an interactive way and precisely to clarify the outputs of programs
I agree. 'Tagged objects' are created on the stack and the tag seems relevant only in the stack environment. Here is an extract from the HP-48 Insights book by Bill Wickes (G/GX edition), about tagged objects:
Quote:
3.4.8 Tagged Objects
Tagged objects (object type 12) are objects used for putting visible labels on stack.
[..]
The beauty of tagged objects is that normally you don’t have to worry about striping tags: a tagged object can be used as an argument for any operation that works with its untagged objects. Most operations apply directly to the untagged object, automatically stripping its tags (including multiple tags). The only exceptions to this rule are:
  • Stack operations that just move or duplicate objects on the stack treat tagged objects like any other object, leaving the tags intact.
  • STO of a tagged object into a local variable or a backup object doe not strip tags (STO into a global variable does strip tags).
  • SAME (section 9.3.2) include tags when comparing two objects.
  • OBJ-> and DTAG remove tags.
  • TYPE returns type 12 for tagged objects.

However it is possible to keep tags when storing objects as shown in various topics on comp.sys.hp48, for example:
Quote:
How can i save a tagged object... ?
> Is there any way to STO a tagged object into a variable...
> or I'm doing something wrong...?

Almost every HP 48 function removes the tags from arguments. This includes STO into a global variable, as you noticed.

However, STO into a local variable, or into a backup object, preserves the tags. That's one way you can solve your dilemma.

[Wicked digression: Try this. 0:FRED DUP STO 25 MENU. Now try to purge 0:FRED. There are several simple ways; don't give up!]

To store a tagged object into a global variable, enclose it inside a program. For example, << :0:CLEM >> can be stored in UH. Then you just press UH, and 0:CLEM will go onto the stack. (Don't use RCL).

A programmable way to change a tagged object into a program is:

# 63FE7h SYSEVAL

This is called "Ob>Seco" in System RPL. It encloses any object in System RPL program delimiters which are invisible but work just fine.
You'll notice in this example that "0: CLEM" turns into ":0: CLEM", making the leading colon visible.

-jkh-


See also this second example for another way to store objects with tags:
Quote:
STO (tagged objects)
> I wanted a TAGGED object stored, with its tag.
> Is there any known repercussions involving this?
> I could re-write pretty easily HP's STO program,
> and store it in a library, and use it everywhere else,
> but if it can crash my baby...

To store a TAGGED object use the sysRPL command ?STO_HERE (actually almost any sysRPL storage command will work, but this one is generally more user friendly). If you want to use this from within a user RPL program it can be accessed using the following SYSEVAL:

#18513h SYSEVAL @ call ?STO_HERE from user RPL

You can easily write a little program such as:

\<< #18513h SYSEVAL \>>

which will save a tagged object. To test it try

2: Tagged object--or any object, just like STO
1: name of global variable

evaluate the program.

Is it safe? It works fine on the HP48SX and HP48G since ?STO_HERE is a supported entry point (and since I tested it on both).

Will it crash your baby...? Until you try you'll never really know, will you?
John


                        
Re: RPL: STO removes tags
Message #12 Posted by Gilles Carpentier on 14 Mar 2012, 1:34 p.m.,
in response to message #11 by Didier Lachieze

thank you for these informations ! Very interesting...


[ Return to Index | Top of Index ]

Go back to the main exhibit hall