Next: , Previous: , Up: Data Types   [Contents][Index]

4.14 Variables

A variable is somewhere between a storage register on a conventional calculator, and a variable in a programming language. (In fact, a Calc variable is really just an Emacs Lisp variable that contains a Calc number or formula.) A variable’s name is normally composed of letters and digits. Calc also allows apostrophes and # signs in variable names. (The Calc variable foo corresponds to the Emacs Lisp variable var-foo, but unless you access the variable from within Emacs Lisp, you don’t need to worry about it. Variable names in algebraic formulas implicitly have ‘var-’ prefixed to their names. The ‘#’ character in variable names used in algebraic formulas corresponds to a dash ‘-’ in the Lisp variable name. If the name contains any dashes, the prefix ‘var-’ is not automatically added. Thus the two formulas ‘foo + 1’ and ‘var#foo + 1’ both refer to the same variable.)

In a command that takes a variable name, you can either type the full name of a variable, or type a single digit to use one of the special convenience variables q0 through q9. For example, 3 s s 2 stores the number 3 in variable q2, and 3 s s foo RET stores that number in variable foo.

To push a variable itself (as opposed to the variable’s value) on the stack, enter its name as an algebraic expression using the apostrophe (') key.

The = (calc-evaluate) key “evaluates” a formula by replacing all variables in the formula which have been given values by a calc-store or calc-let command by their stored values. Other variables are left alone. Thus a variable that has not been stored acts like an abstract variable in algebra; a variable that has been stored acts more like a register in a traditional calculator. With a positive numeric prefix argument, = evaluates the top n stack entries; with a negative argument, = evaluates the nth stack entry.

A few variables are called special constants. Their names are ‘e’, ‘pi’, ‘i’, ‘phi’, and ‘gamma’. (See Scientific Functions.) When they are evaluated with =, their values are calculated if necessary according to the current precision or complex polar mode. If you wish to use these symbols for other purposes, simply undefine or redefine them using calc-store.

The variables ‘inf’, ‘uinf’, and ‘nan’ stand for infinite or indeterminate values. It’s best not to use them as regular variables, since Calc uses special algebraic rules when it manipulates them. Calc displays a warning message if you store a value into any of these special variables.

See Storing and Recalling, for a discussion of commands dealing with variables.

Next: Formulas, Previous: Incomplete Objects, Up: Data Types   [Contents][Index]