0
votes

I'm new to Prolog and what I want to achieve is to perform an operation like append/3 over two lists that are saved in my program. I don't need to open swi-prolog and type append([a,b,c],[h,j,k],X). in order to obtain X=[a,b,c,h,j,k]. What I need is something like retrieve two lists from the program and perform the append over them. I don't even know if what I want to obtain is possible in Prolog.

This is my situation: I got this "esempio.pl" file where I have the following rule and these two facts:

personal_union(F,C,Xs) :- 
   personal_list(F,Fs),personal_list(C,Cs),append(Fs,Cs,Xs).
personal_list(family,[alessandro,cinzia,fabio]).
personal_list(colors,[blu,giallo,lilla,verde,rosso]).

I'd like to question "esempio.pl" from SWI-prolog and ask it:

personal_union(family,colors,X).

And obtain the unified lists:

X=[alessandro,cinzia,fabio,blu,giallo,lilla,verde,rosso]`

Is my code a possible solution? I couldn't try it myself because it keeps giving me this error: Syntax error: illegal start of term stating that the error is at the start of the body of my rule.

1

1 Answers

0
votes

Your code is valid as I tested it on Swish, and it produces the requested result.

The error you get is usually derived of mistaken syntax such as additional commas or brackets issues. Check the rest of you code. Also, you might find http://swish.swi-prolog.org/ comfortable for such debugging.