The expr( Command

Command Summary

Returns the value of a string that contains an expression.

Command Syntax


Menu Location

This command is found only in the Catalog. Press:

  1. 2ND CATALOG to enter the catalog
  2. F to go to commands starting with F
  3. Scroll up a bit to expr(.

Calculator Compatibility


Token Size

2 bytes

The expr( command is used to evaluate an expression that's stored in a string (an expression is merely anything that returns a value - of any type). Expressions are occasionally stored to strings, rather than evaluated outright, so that their value has the capacity to change when the variables stored inside them change. The expr( command's result depends on the kind of expression that's in the string you pass it — it may return a number, a list, a matrix, or even another string.

As a special case of an expression, the expr( command can also be used to convert a string like "123" to the number 123. Going in the reverse direction (123 to "123") is more complicated.

The expr( command has limitations. Here are the situations in which expr( will not work:

  • When the code in the string does not return an answer, and thus is not an expression: e.g. expr("Line(0,0,1,1" or expr("prgmHELLO" is invalid
  • When the expression in the string contains an expr( command itself, e.g. expr("expr(Str1" — this will throw an ERR:ILLEGAL NEST error.
  • In place of a variable (rather than an expression), e.g. 5→expr("X" isn't a substitute for 5→X because expr("X" evaluates to the value of X and not to X itself.

Advanced Uses

expr( is often used in conjunction with the Input command to prompt the user to enter a list. Although the Input command can already handle lists, it requires the user to enter the opening bracket that signifies a list. With expr(, this can be avoided.

Instead of:

:Input L1

Use this:
:Input Str1


Evaluating an expression inside a string is more complicated than evaluating a normal expression; you should therefore try to take as much out of an expr( statement as possible to speed up your code. For example:

can be

Error Conditions

  • ERR:ILLEGAL NEST is thrown when the string to be evaluated contains an expr( itself.
  • ERR:INVALID is thrown when trying to evaluate the empty string.
  • ERR:SYNTAX is thrown when trying to evaluate a command that doesn't return a value.

Related Commands


Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License