The Escape Character

Jordi Hidalgo, #1046

It is a well-known fact that variable names on the HP48 and HP49 can’t contain function symbols or characters that separate or delimit objects (HP48G User’s Guide, page 5-5). I knew only one method to include such characters in a global or local name: via the system word $>ID (SYSEVAL address #5B15h). But there’s another one, and it creates "legal" names!

In many character code sets (those based on ASCII), character code 27 is known as the escape character. Some HP calcs use it to generate printer control sequences. For instance, printing this string:

"\027ûHPCC\027ú"

would show our club’s name underlined (on that expensive thermal paper, by the way). The symbol \027 means the character with decimal code 27, which is seen as a little black square. On the HP48G or HP49G one can use the CHARS application to include it in the command line. On the HP48S, type 27 CHR and press the down arrow key. (For convenience you can assign it to a key). See page 22 of your printer’s manual for additional escape codes.

The escape character can also be used to suppress the normal meaning of special characters (such as #, ", ', +). Just enter it before the special character you want to use. Hence, typing in '\027#' would return that global name to stack level one. The name formed is perfectly legal, in the sense that it can be edited in the command line, included in user programs or in equations.

I’ve noticed two curious tips.

Type \027 (without quotes) and press ENTER. It returns the name '\027' (if it exists somewhere in your path, its value is returned instead). Now enter: '\027'. The variable created now is '\027'' (with two ending ticks!)

More weird names? Try with the characters space or new-line. It works with any character. Even with the null one (code 0). It cannot be entered directly, since it’s used for marking the end of the command line. Let’s use this program:

<< "'" 27 CHR + 0 CHR + "ABC" + OBJ-> >>

The first object is a single quote enclosed in two double quotes. It puts the variable '\027\000ABC' unevaluated into level one. (Run that program later again to purge this variable, or use the variable browser or the filer). Let’s store something now: "Hi" SWAP STO.

Would you like to insert the null character in the command line? If you try to invoke that name in Immediate-entry or Program-entry modes, the error message "Can't Edit Null Char." is displayed. But on the HP48 there’s no error if Algebraic-entry mode is active (not sure if it’s really a bug, but anyway it’s "fixed" in the HP49G!):

On an HP48 press ' or right shift + ALPHA twice, press VAR and then press the softkey corresponding to the name with the null character. Press the left arrow key till the beginning of line, and then the right arrow key till the end. Can you "see" it now? ;-)


johil@tv3mail.com
Page last modified : 27th May 2002