我需要在Prolog中获取一个术语的参数的索引。谓词arg / 3似乎与我需要的相反:
arg(Index, Term, Value).
arg/3
如果Index是变量,则失败,因此不可能获得给定值和项的索引。你们知道实现此目的的其他方法(我不能使用外部库)?
预期行为的一个例子是:
?- arg_(Index, regs(a,b,c), c).
Index = 3
按我的预期工作。
唯一的区别是您使用了arg_
,而我使用了arg
。
Welcome to SWI-Prolog (threaded, 64 bits, version 8.1.24)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.
For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).
?- arg(Index,regs(a,b,c),c).
Index = 3.
?- arg(Index,s(a,b,c,d),V).
Index = 1,
V = a ;
Index = 2,
V = b ;
Index = 3,
V = c ;
Index = 4,
V = d.