检查列表是否已定义并避免出现“UNDEFINED”。错误
在原始的 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.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,似乎没有一个干净、简单的函数来检查列表是否已经存在,但感谢 harold 将其作为评论发布,有一个解决方法:
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:
如果您在列表的创建过程中拥有控制权,那么另一种解决方法是使用另一个仅包含一个元素的列表(或另一个固定大小的列表或字母变量)作为指示此主列表存在的标志。
对于列表 LMAIN 和 LFLAG 来说,类似这样:
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: