Next Previous Contents

14. Using the memory

Besides the stack, all objects that can be present in calc can also be stored in another place: the memory. This is a permanent place of storage, and has no fixed size: you can store as many objects as your memory can hold.

To store an object in memory, you must give it a name, which will be used to bring that object back whenever you want to. A name in calc is called an identifier. It is like a string, but it is delimited by single quotes. Unlike in the HP48 calculator, identifiers in calc can contain any character, including characters invalid in the HP48 such as space, +, *, etc. The identifier may even by the empty name: ''.

To store an object, put that object in level two of the stack, and on level one an identifier. Then run the command sto. This will store the object.

To recall an object from memory, put in the stack the name of the object, and run the rcl command. The stack will contain a copy of the object, but the memory will not be affected -- you can recall any object as many times as you want.

There is an easier way to recall objects: instead of entering the identifier between single quotes and running rcl, just enter the object's name without quotes, as if it were a command. You'll get the object in the stack. If there is no object with that name, you'll get the indentifier in the stack. This will not work if the name has spaces, however -- in this case you'll need to first put the identifier in the stack and then run the rcl command.

When you exit calc the contents of the memory are stored in the init file (see section The Init File), and restored when you run calc again, unless you use the -m command line switch (see section Command Line Options).

Here are some examples of the use of memory:

> pi
[ 1]          3.14159265358979
> 'AConstant'
[ 2]          3.14159265358979
[ 1]               'AConstant'
> sto
> 'AConstant'
[ 1]               'AConstant'
> rcl
[ 1]          3.14159265358979
> AConstant
[ 2]          3.14159265358979
[ 1]          3.14159265358979

14.1 Listing and erasing the memory

When you want to see all the objects that are stored in memory, use the vars command. It will output the names of all the stored objects. Here is one example, assuming 'AConstant' is still in memory:

> 1 exp 'Another Constant'
[ 2]          2.71828182845905
[ 1]        'Another Constant'
> sto
> "Hello World"
[ 1]             "Hello World"
> 'String'
[ 2]             "Hello World"
[ 1]                  'String'
> sto
> (3, -2) 'cmp' sto
> vars
'AConstant' 'cmp' 'String'
'Another Constant'

To erase one object from the memory, put that object's name in the stack and run the purge command. But be careful: there is no way to bring back an erased object.

If you want to get rid of the whole memory, use the clvar command. This command will erase all your memory, and there is no way to bring back the erased memory. Because of this, the commands asks you for confirmation before doing the operation.

14.2 Saving objects to the disk

In addition to saving objects in calc's memory, objects can also be saved to the disk. To do this, put the object in level two, and the path of the file you want to save in level one (this is an identifier). Then run the disksto command. The object will be saved to the named file.

To recall an object from a file, put the file's path (an identifier) in the stack, and run the diskrcl command. If the file contains a valid object, it will be loaded in level one.

If you give a relative path as the name of the file, it is considered as relative to the current working directory. To discover which directory is this, run the pwd command. It will output the directory. To change the current directory, put the directory you want to go to in level one (an identifier) and run the cd command.


Next Previous Contents