Enter RPN

R47: Variables
Login

R47: Variables

Motivation

Plenty has been written on the subject of variables in the context of RPN programming, but we find a need to cover the R47-specific details here. This will inevitably repeat material that past users of the HP-42S — or the HP-41 series before it — will already be familiar with, but since there will be a segment of the audience lacking that grounding, your humble author views this as an intentional feature of the presentation.

What Are Variables, Anyway?

Like all calculators in its evolutionary line, the R47 uses the CS meaning of “variable,” not the mathematical one. The distinction is not as important in this context because RPN does not abuse the = sign to mean both equality and assignment, as happens in common computer programming languages. Whereas we might say this in a C program…

#include <math.h>
float f = PI / 2;

…we might instead say on our R47…

🟧 π 2 ÷
STO ‘f’

This syntactic difference makes clear that we are not making a durable assertion `f=π/2` but are merely storing a value for later use.

C tries to have it both ways via its const keyword, but as loose as C is about sticking to rules, it’s more a suggestion than a mathematical assertion. Contrast F#, where the syntax is ironclad:

let f = System.Math.PI / 2.0
let mutable mf = f
mf <- 42.0           // free to reassign it, but not by abusing “=”
f  <- 42.0           // compile error!

Although math is the R47’s game, the closest it comes to allowing similar assertions of mathematical facts are in its equation editor and solver features. When it comes to variable use, it is important to realize that we are free to STO another value in any named location at any future time. The only case where a value is read-only on the R47 is with a subset of the system flags.

Variables on the R47 are like registers in that they contain data-typed values, but both are looser even than C in this regard because the data type can change over time. The R47 is more like a dynamic programming language in this respect.

Another key distinction is that variables are named, while registers are numbered. Although there is a superficial overlap when it comes to the single-lettered registers, most of these are off-limits for general-purpose use in the R47. Our interest here is limited to proper variables, which means the quoted form shown above.

A more obscure detail distinguishing the two is that there is never a state of the calculator where the A-Z registers do not exist, whereas the variables ’A’ thru ’Z’ must have something STO’d into them before they exist. Why does it matter? Because you can RCL a named register at any time, but if you do that with a variable that does not exist yet, you get an error. The closest registers get to this is the “cleared” state, meaning they are set to a real-typed zero.

Naming

R47 variable names appear between single curled quotes1 to distinguish them. Operations like STO and RCL can then refer to these values by name.

These names are case-sensitive in the R47, which means this…

STO ‘f’
STO ‘F’
STO F

…stores the X register’s contents into three different memory locations, the last of which we know to be another register — not a variable — by the lack of curled single quote marks.

Variable names may be up to 7 characters long. When entering a variable name, hitting that limit automatically closes the entry; it doesn’t just beep at you stupidly until you give up and hit ENTER. The downside of this helpful (?) design is that none of the prior six characters closed the entry, leading to an unmet expectation that you could continue editing the name after giving the seventh character. To see what I mean, try this:

STO ‘abcdefg’

Notice that the new variable name appears to the left of the X value immediately on hitting the g key.

Alpha Modes

That brings us to how one enters those letters in the first place.

If you tried my example above but pressed STO and then the 𝑥² key to get the “A” printed in white next to it, what you will have actually done is stored the value in the A register, not begun the 7-character name suggested above. Worse, because the R47 defaults to an 8-level stack where the upper four levels use the registers A-D, the next stack operation will likely either push that up into register B or drop it down into T.

The simplest way on the R47 to begin specifying a named STO target variable rather than a register is to press the XEQ key, which enters temporary alpha mode, or TAM for short. This caused an open curly quote to appear in the STO target field, which is why pressing the 𝑥² key now gives a lowercase “a” without closing the entry. This then allows us to proceed with “b” and so forth until wee see the automatic quote closure on hitting the “g” in the above example.

You might not immediately see why pressing XEQ makes sense here. It is a variation on 🟧 α, which enters the full-strength non-temporary alpha mode, meaning that it might continue on in that mode even after the immediate entry is complete. Not in this case, though, which is the second reason I showed you TAM first.

(If TAM is the sensible path for variable naming, why did I show the other way in my program entry article? Because that was introductory material where I deemed clarity more valuable than keystroke economy. I did not want to go into all this explanatory detail in the middle of that tutorial.)

Regardless, press the 🟧 key in either alpha mode to toggle between lowercase and capital letters. Press 🟦 to toggle between letters and numbers. The R47 alphabet is roughly as extensive as early Unicode 1.0 implementations, which is why a menu comes up for selecting from other subsets of its impressive — for a handheld calculator — character set.

Historical Restrictions

The mixed ancestry leading to the R47 had several restrictions on how variables could be named. Early C47 releases shared some of these, but the last were finally lifted shortly before the first production R47 units shipped, in version 0.109.02.07b12.

These limitations were intended to avoid assorted collisions, but meeting that laudable goal not only left a rather small set of valid single-letter names for user programs, it made conversion from the HP-32S family difficult because its naming scheme allowed all 26 English alphabet letters without restriction.

We may distill the new rules as:

  1. Predefined constants are marked with a leading # in contexts where a conflict might occur. Thus ‘c’ is always a variable name, while #c is the speed-of-light constant.

  2. Lowercase letters can now be used without restriction for variables as a result.

  3. Single uppercase letters are distinguished from the named registers by use of single-quoted alpha string syntax, as we saw above.

This unification is one of those hidden improvements in the R47 that a good many users will never even realize exists, taking sensible operation without surprising exception cases for granted.

(You may now wish to return to my R47 article index.)

License

This work is © 2026 by Warren Young and is licensed under CC BY-NC-SA 4.0


  1. ^ The HP-42S and HP-41 lines that the R47 and its lineal ancestors spiritually descend from used straight ASCII double quotes instead. Same thing.