Eg: ["c","h","a","r"] should print "char".
its atomic_list_concat(), but how would I do it for eg:
longest_common_prefix([H1,H2|T], P) :-
maplist(append(P), L, [H1,H2|T]).
Using library(double_quotes)
as described here, we can use append/2
(note the 2!) :
?- set_prolog_flag(double_quotes).
true.
?- append(["c","h","a","r"], Cs).
Cs = "char".
However, please note that "c"
is not a character! It is a list with one character. One single character is c
alone. And most of the times, you do not need to write "c"
?- [c,h,a,r] = "char".
true.
in SWI-Prolog
?- atomic_list_concat( ["c","h","a","r"] , L).
L = char.
but things become hairier soon... you should take the time to learn about elementary data representation for anything serious