Question

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 .

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top