不允许使用列表中的缺点; "does not match any of the declared (overloaded) signature patterns"



根据此页面:

http://tutor.rascal-mpl.org/Rascalopedia/List/List.html

这是您在列表中使用缺点的方式:

cons(1,[2,3]); //should return [1,2,3]

在流氓控制台中尝试此操作:

import List;
cons(1,[2,3]);

给我这个错误:

|stdin:///|(1,13,<1,1>,<1,14>): The called signature: cons(int, list[int]),
does not match any of the declared (overloaded) signature patterns:
    Symbol = cons(Symbol,str,list[Symbol])
    Production = cons(Symbol,list[Symbol],set[Attr])
    Symbol = cons(Symbol,str,list[Symbol])
    Production = cons(Symbol,list[Symbol],set[Attr])

与标准导入的函数和数据类型是否存在名称冲突?

好问题。首先是直截了当的答案。Cons 不作为用于构建列表的库函数存在(它是化类型 API 的一部分,意思不同)。

我们这样写:

rascal>[1, *[2,3,4]]
list[int]: [1,2,3,4]
rascal>1 + [2,3,4]
list[int]: [1,2,3,4]
rascal>[1] + [2,3,4]
list[int]: [1,2,3,4]
rascal>list[int] myList(int i) = [0..i];
list[int] (int): list[int] myList(int);
rascal>[*myList(10), *myList(20)]
list[int]: [0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]

现在解释一下混乱。流氓百科课程是关于抽象概念和术语的,通常在与流氓合作时最好知道。这对您来说可能太基本了。我将专注于 Rascal 语言和库课程,以获取与 Rascal 编程相关的更具体的示例和信息。有关列表文本,请参阅 http://tutor.rascal-mpl.org/Rascal/Expressions/Values/List/List.html,有关列表上的库函数,请参阅 http://tutor.rascal-mpl.org/Rascal/Libraries/Prelude/List/List.html。

其他一些列表方便,用于解构而不是构造:

rascal>[1,2,3,4][1..]
list[int]: [2,3,4]
rascal>[1,2,3,4][1..2]
list[int]: [2]
rascal>[1,2,3,4][..-1]
list[int]: [1,2,3]
rascal>if ([*x, *y] := [1,2,3,4], size(x) == size(y)) println(<x,y>);
<[1,2],[3,4]>
ok
rascal>for ([*x, *y] := [1,2,3,4]) println(<x,y>);
<[],[1,2,3,4]>
<[1],[2,3,4]>
<[1,2],[3,4]>
<[1,2,3],[4]>
<[1,2,3,4],[]>

相关内容

最新更新