Skip to content
Property Value
Hex Value $BB2A
Categories
Localizations
  • FR: expr(

expr(

Overview

Converts the character string contained in string to an expression and executes the expression. string can be a string or a string variable.

Availability: Token only available from within the Basic editor.

Syntax

expr(string)

Arguments

NameTypeOptional
stringstring

Location

prgm


Description

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 Usage with Lists

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.

If you want the user to enter a list separated by commas, instead of:

Input L₁

Use this:

Input Str1
expr("{"+Str1→L₁

This will automatically put the curly bracket in so the user does not have to.

Just be aware that you cannot access individual list items directly after the expr() function, unlike how you can with Ans. The following code will multiply the entire list by 2 rather than return the second item:

expr("{1,2}")(2)

Instead, to access the second item in the list you could split this across two lines and use Ans:

expr("{1,2}")
Ans(2)

Optimization

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:

expr("sum({"+Str1

can be:

sum(expr("{"+Str1

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.

Source: parts of this page were written by the following TI|BD contributors: burr, DarkerLine, GoVegan.

History

Calculator OS Version Description
TI-83 0.01013 Added

Last update: July 29, 2024 19:47:40
Created: February 23, 2023 23:15:01
Authors: Adrien Bertrand