RPL: STO removes tags



#13

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


#14

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.


#15

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 ?


#16

Salut C.Ret ;D

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


#17

Right,

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

#18

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.

#19

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.


#20

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


#21

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.

#22

"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.

#23

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



#24

thank you for these informations ! Very interesting...


Possibly Related Threads...
Thread Author Replies Views Last Post
  Writing RPL programs on OS X Sean Freeman 18 1,784 11-30-2013, 03:59 PM
Last Post: Sean Freeman
  48G vs 49G+ User RPL Speed Comparison John Colvin 7 793 11-16-2013, 10:07 PM
Last Post: Han
  RPL 32 David Hayden 4 657 11-11-2013, 11:34 AM
Last Post: David Hayden
  HHC / HP Museum Programming Contest for RPN and RPL machines Gene Wright 18 1,659 09-22-2013, 09:39 AM
Last Post: Miguel Toro
  HP Prime - How to STO in RPN mode? Javier Goizueta 10 887 08-18-2013, 10:24 PM
Last Post: Xavier A. (Brazil)
  RPL long vs. short names peacecalc 5 668 10-30-2012, 01:25 PM
Last Post: peacecalc
  Mini-challenge: HHC2012 RPL programming contest with larger input David Hayden 14 1,308 10-05-2012, 10:36 PM
Last Post: David Hayden
  HHC 2012 RPL Programming Contest Gene Wright 33 2,477 09-27-2012, 01:57 AM
Last Post: Werner
  HHC 2012 programming contests coming soon (RPN and RPL) Gene Wright 9 949 09-21-2012, 03:38 PM
Last Post: Paul Dale
  RPL prog for Fibonacci on HP 48G needs minor modification. help. wildpig 68 4,086 07-09-2012, 09:38 AM
Last Post: Gilles Carpentier

Forum Jump: