TI-列表中的基本存储公式

TI-Basic Storing Formula In a List

我最近发现 TI-Basic 的一个奇怪行为允许程序员将公式存储到列表变量中。这些年来,我已经对 TI-Basic 非常熟悉,并且检查了来自 TI-Basic Developer Forum, This Whosebug tag and a Subreddit 等专门用于 TI-Basic 的来源的代码示例,除了承认它的存在之外没有发现任何其他内容。


创建此行为的语法很简单:

<String>→<List>

其中 <String> 表示任何字符串、文字或变量。实验表明此 String 必须计算为一个列表。 <List> 表示一个列表变量。使用列表文字将导致 ERR:SYNTAX.

为了帮助理解我所描述的内容,这里有一些使用实际代码的示例:

"X+2→L₁

"2L₁→L₂

两个例子最初都会运行;但是,如果我尝试在第一个示例中访问 L₁,我会得到 ERR:DATA TYPE。访问 L₂ 将 return 是 L₁.

当前值的两倍

由于这个问题到目前为止是对这种行为的描述,没有直接的问题,我将通过列举一些回答可以回答的具体问题来总结。

  1. 我是否正确陈述了此行为的语法?
  2. 此行为有哪些可能的用例?
  3. 在哪里可以找到此行为的官方文档?

这些只是关于答案可以包含的内容的建议。我很乐意接受对这种行为的全面和一般的分析。

很高兴回答您的问题:)

  1. 差不多。在这种行为中,列表变量与图形变量(函数、极坐标、顺序变量等)在存储字符串方面的关系最为密切。这使得它在任何可以应用 self-modifying code 的地方都很有用。
  2. 基本上,主要有两个用途——自修改代码和优化。您主要指的是用作优化,您将冗长的公式存储到变量中以供快速参考。调用列表时必须 return 一个列表,这就是为什么你的第一个示例 "X+2→L₁ 失败但 "2L₁→L₂ 成功 return 一个列表的原因。例如,L1 可用于存储 return 列表的任何方程。如果您想获得 1-10 的 10 个非重复数字的列表,您可以在任何需要的地方使用 randIntNoRep(1,10),7 个字节(或 6 个未闭合的字节)。但是,"randIntNoRep(1,10)->L1 允许您随时调用 L1 以重新调用 10 个随机数。请注意,如果不是字符串格式(例如 randIntNoRep(1,10)->L1),它会起作用,但每次调用 L1 都会 return 相同的数字列表,因为它是静态存储的。此外,如果等式默认情况下没有 return 列表,您始终可以在开头添加列表括号,但由于只有一个元素,使用函数或序列变量会更聪明(我的个人最喜欢的是u)。此功能的另一个具体用途是在 Number or String 例程中,用于检测 Ans 是数字还是字符串。
  3. 我不知道官方对此有何记载,因为不幸的是我没有手册可供参考。如果您还有其他问题,我很乐意为您解答。

回复原文中列出的第三个问题post,

Where can I find official documentation of this behavior?

827 page TI-83 manual 的 PDF 可从田纳西大学工程学院在线获取。本手册包含绝大多数 TI-Basic 功能的文档,包括原始 post 中描述的功能。

与问题相关的手册部分从第 296 页开始,一直持续到第 299 页。

Attaching Formulas to List Names

Attaching a Formula to a List Name

You can attach a formula to a list name so that each list element is a result of the formula. When executed, the attached formula must resolve to a list.

When anything in the attached formula changes, the list to which the formula is attached is updated automatically.

  • When you edit an element of a list that is referenced in the formula, the corresponding element in the list to which the formula is attached is updated.
  • When you edit the formula itself, all elements in the list to which the formula is attached are updated.

For example, the first screen below shows that elements are stored to L₃, and the formula L₃+10 is attached to the list name ʟADD10 The quotation marks designate the formula to be attached to ʟADD10. Each element of ʟADD10 is the sum of an element in L₃ and 10.

The next screen shows another list, L₄. The elements of L₄ are the sum of the same formula that is attached to L₃. However, quotation marks are not entered, so the formula is not attached to L₄.

On the next line, ⁻6→L₃(1):L₃ changes the first element of L₃ to ⁻6, and then redisplays L₃.

The last screen shows that editing L₃ updated ʟAdd10, but did not change L₄. This is because the formula L₃+10 is attached to ʟADD10, but it is not attached to l4

手册的格式与 Whosebug 不一致,因此我不得不为这个答案重新格式化它。