Search code examples
listfunctionti-basic

TI-Basic Storing Formula In a List


I recently became aware of an odd behavior of TI-Basic that allows the programmer to store a formula into a list variable. I've become quite familiar with TI-Basic over the years and have examined samples of code from sources such as TI-Basic Developer Forum, This StackOverflow tag and a Subreddit devoted to TI-Basic without finding anything other than acknowledgement of its existence .


The syntax to create this behavior is simple:

<String>→<List>

where <String> represents any string , literal or variable. Experimentation has shown that this String must evaluate to a list. <List> represents a list variable. Using a list literal will result in ERR:SYNTAX.

To help with understanding what I am describing, here are some examples using actual code:

"X+2→L₁

"2L₁→L₂

Both example will run initially; however, if I try to access L₁ in the first example, I get ERR:DATA TYPE. Accessing L₂ will return two times the current value of L₁.


As this question has so far been a description of this behavior without a direct question, I will conclude by enumeration some specific questions that responses could answer.

  1. Have I correctly stated the syntax of this behavior?
  2. What are some possible use cases for this behavior?
  3. Where can I find official documentation of this behavior?

These are just recommendations for what an answer could include. I will be happy to accept a well rounded and general analysis of this behavior.


Solution

  • Glad to answer a question of yours :)

    1. Pretty much. The list variables are most closely related in this behavior to graphing variables - function, polar, sequential, etc. in their ability to store the string. This makes it useful wherever self-modifying code can be applied.
    2. Basically, there are two main uses - self-modifying code and optimization. You're referring mainly to the use as optimization, where you store a lengthy formula into a variable for quick reference. Lists must return a list when called, so that's why your first example "X+2→L₁ fails but "2L₁→L₂ successfully returns a list. For example, L1 can be used to store any equation that returns a list. If you wanted to get a list of 10 non-repeating numbers from 1-10, you would use randIntNoRep(1,10), 7 bytes (or 6 when unclosed), wherever you needed it. However, doing "randIntNoRep(1,10)->L1 allows you to call L1 anytime for a fresh call of the 10 random numbers. Note that when not in string format (e.g. randIntNoRep(1,10)->L1), it will work, but each call to L1 will return the same list of numbers, since it is statically stored. Additionally, if the equation doesn't return a list by default, you can always add a list bracket at the beginning, but since there is only one element it would be much smarter to use a function or sequence variable (my personal favorite is u). Another specific use of this functionality is in the Number or String routine, for detecting whether Ans is a number or a string.
    3. I don't know anyplace where this is officially documented, since unfortunately I don't have the manual to reference. If you have any additional questions, I'd be happy to answer them for you.