首页 > 解决方案 > 在 Prolog 中获取运算符谓词的结果

问题描述

我试图了解运营商。

我为它定义了以下运算符和方法。

:-  op(600,  xfy,  ⧺). 

⧺(Left, Right) :- concatAtoms([Left, Right], _). % _ would the result but can´t be returned without an extra parameter

% concatenates atoms, e.g. [a,b] = ab
concatAtoms([H|T], R) :-
    concatAtoms(T, H, R).

concatAtoms([], R, R).
concatAtoms([H|T], Atom, R) :-
    atom_concat(Atom, H, Res),
    concatAtoms(T, Res, R).

查询

?- a⧺b.

按预期返回 true。

有没有办法让它回来

ab

而是(由 concatAtoms 谓词计算)?

标签: prologoperators

解决方案



推荐阅读