1

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

index? find x "two"返回... 2

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

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

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

4

1 回答 1

0
>> 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
于 2019-12-01T08:26:11.480 回答