简体   繁体   中英

Prolog predicate to find intersection of 2 lists outputting list of G followed by numbers [G2252,G2255]

correct_letters([],L2,[]).

correct_letters([L1|T1],L2,[L3|T3]) :-
    list_helper1(L1,L2),
    correct_letters(T1,L2,T3).

correct_letters([L1|T1],L2,CL) :-
    \+ list_helper1(L1,L2),
    correct_letters(T1,L2,CL).


list_helper1(F,[F|_]).
list_helper1(F,[_|T]) :-
    list_helper1(F,T).

This code to return the intersection of two lists returns G followed by numbers. For example when inputs [1,2,3,4] and [1,3] are given output is CL = [_G2252, _G2255] . how do I make the output normal letters and numbers

_G2252 and similar are unbound variables, they are variables you have named without giving Prolog any reason to bind them to a value.

how do I make the output normal letters and numbers

L3 should be L1 in this line:

correct_letters([L1|T1],L2,[L3|T3]) :-

at the moment it says "if L1 is found in L2, put an unknown variable in the third list". It should say "if L1 is found in L2, put L1 in the third list".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM