prolog atom concat swi and yap prolog
input :
run([p(X,Y,Z),h(Z,P,Q)],Out).
code:
:- ensure_loaded(library(lists)).
run([X|Y],Out) :-
X =.. [Fct|Args],
X =..Total,
length(Args,L),
concat(abs_,L,Fct_A),
Out =.. [Fct_A|Total].
on swi prolog i get the right answer:
A = abs_3(p, X, Y,开发者_运维百科 Z).
on yap prolog fail. Seen that i should use yap.
what i have to use instead of concat(abs_,L,Fct_A)
? i tried atom_codes but it append strange ascii on the end of the atom. please help .
In this case SWI is incorrect. The goal atom_concat(a,1,X)
has to produce a type error according to ISO ; and IF, YAP, B, GNU, SICStus, XSB, Ciao all behave that way. In ISO, there is atom_chars/2
and number_chars/2
. So what you want is
atom_number_concat(A, N, AN) :-
number_chars(N, Chs),
atom_chars(Na, Chs),
atom_concat(A, Na, AN).
YAP has a special built-in atom_number/2
which would replace the first two goals.
精彩评论