Prolog 将结果标记到列表中?

Prolog 将结果标记到列表中?,prolog,clpfd,Prolog,Clpfd,我想写一个谓词,可以使用predict lucky/5对所有幸运数字求和 :- use_module(library(clpfd)). lucky(A,B,C,D,N) :- L = [A,B,C,D], L ins 0..9, N #= A*1000+B*100+C*10+D, A+B #= C+D, labeling([],L). sum_all():- % I want to write a code that computes the sum of all lucky numbers

我想写一个谓词,可以使用predict lucky/5对所有幸运数字求和

:- use_module(library(clpfd)).

lucky(A,B,C,D,N) :-
L = [A,B,C,D],
L ins 0..9,
N #= A*1000+B*100+C*10+D,
A+B #= C+D,
labeling([],L).

sum_all():-
% I want to write a code that computes the sum of all lucky numbers
如果Prolog具有library(),则可以执行以下操作

?- aggregate_all((count,sum(N)), lucky(_,_,_,_,N), (Count,Sum)).
Count = 670,
Sum = 3349665.
sum_all():-…
是一个语法错误。Prolog不会将该语法用于空参数列表。