定义
*$pattern在pyke中用来匹配不能确定长度的tuple模式。
必须出现在tuple模式匹配中
根据这个定义,我们首先得出第一条规则,*$pattern必须出现在tuple模式匹配之中。例如:
use someRule($value0, $value1, ($inValue0, *$theRest))
并且这样的方式不能出现在非tuple的匹配中。例如下面这样:
use someRule($value0, $value1, *$theRest) #不能这样使用
必须出现在tuple模式匹配的后面
pyke解释器在很大程度上是参照python的,*$pattern只能出现tuple的最后。像下面这样是不行的:
use someRule($value0, $value1, ($inValue0, *$theRest, $theLast))
在规则内部对*$pattern赋值时只能用tuple赋值
非tuple类型的数据给pattern赋值是会报错的。看下面示例
test
use test(($theOne, *$theRest))
when
$theOne = 10
$theRest = (1,2,3,4) #正确
$theRest = (1,) #正确
$theRest = (1) #错误
$theRest = 1 #错误