检查列表是否已定义并避免出现“UNDEFINED”。错误

发布于 2025-01-10 00:14:52 字数 389 浏览 0 评论 0原文

在原始的 TI-BASIC(对于 TI-83/84+)中,有没有办法检查列表是否已定义?

如果列表未定义,当前调用 dim(⌊LIST) 将返回错误。

输入图片这里的描述

有没有办法优雅地处理该错误?

可能的解决方法:
我能想到的唯一的黑客方法是用比您预期更多的项目重新定义列表,例如 99→dim(⌊LIST) 并检查前几个值是否不为零。但这似乎既浪费又缓慢。

有什么建议吗?

In the original TI-BASIC (for TI-83/84+) is there a way to check if a list has been defined?

Currently calling dim(⌊LIST) will return an error if the list is not defined.

enter image description here

Is there a way to handle that error gracefully?

Possible Workaround:
The only hacky way I can think of doing so is to redefine the list with more items than you're expecting such as 99→dim(⌊LIST) and check if the first few values are not zero. But that seems wasteful and slow.

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吖咩 2025-01-17 00:14:52

不幸的是,似乎没有一个干净、简单的函数来检查列表是否已经存在,但感谢 harold 将其作为评论发布,有一个解决方法:

SetUpEditor 命令

这通常用于指定在列表编辑器中显示哪些列表,但该命令具有创建零长度列表(如果尚不存在)的副作用。

这是一些示例代码,带有注释:

"Create two empty lists if they do not exist yet
SetUpEditor FOO,BAR

"Check the size of FOO
dim(∟FOO)→X

"Clean up by returning the list editor back to
"its default state (∟1-∟6)
SetUpEditor 

Unfortunately there doesn't seem to be a clean, simple function for checking if a list already exists, but thanks to harold who posted this as a comment, there is a workaround:

The SetUpEditor command.

This is typically used for specifying which lists are displayed in the list editor, but the command has the side-effect of creating a zero-length list if it does not exist yet.

So here's some sample code, with comments:

"Create two empty lists if they do not exist yet
SetUpEditor FOO,BAR

"Check the size of FOO
dim(∟FOO)→X

"Clean up by returning the list editor back to
"its default state (∟1-∟6)
SetUpEditor 
秋叶绚丽 2025-01-17 00:14:52

如果您在列表的创建过程中拥有控制权,那么另一种解决方法是使用另一个仅包含一个元素的列表(或另一个固定大小的列表或字母变量)作为指示此主列表存在的标志。

对于列表 LMAIN 和 LFLAG 来说,类似这样:

1->dim(LFLAG
If 5784923472≠LFLAG(1
Then
"assume LMAIN does not exist because flag hasn't been set
"insert optional other code here
0->dim(LMAIN
5784923472->LFLAG(1
End

If you have control during the lists's creation, then another workaround would be to use another list with only one element (or a list of another fixed size, or a letter variable) as a flag that indicates this main list exists.

Something like this, for lists LMAIN and LFLAG:

1->dim(LFLAG
If 5784923472≠LFLAG(1
Then
"assume LMAIN does not exist because flag hasn't been set
"insert optional other code here
0->dim(LMAIN
5784923472->LFLAG(1
End
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文