尝试查找索引时处理'none'?Rebol 中不存在的值?



我有一个block!x: ["one" "two" "three"]

index? find x "two"返回...阿拉伯数字

index? find x "four"回归...

** Script Error: index? expected series argument of type: series port ** Near: index? find x "twos"

索引的最佳方法是什么? 返回none而不是错误?

>> help index?
USAGE:
INDEX? series /xy
DESCRIPTION:
Returns the index number of the current position in the series.
INDEX? is an action value.
ARGUMENTS:
series -- (Type: series port)
REFINEMENTS:
/xy -- Returns index as an XY pair offset.

索引? 期待一个系列。如果参数为 none,则会引发错误。

>>  find x "four"
== none

您可以检查参数是否存在或是一个系列或防止错误,例如

>> if  series? i: find x "four" [index? i]
== none

>> attempt [index? find x "four" none]
== none

相关内容

  • 没有找到相关文章

最新更新