Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Prolog 将列表列表合并到单个列表中_Prolog - Fatal编程技术网

Prolog 将列表列表合并到单个列表中

Prolog 将列表列表合并到单个列表中,prolog,Prolog,请遵循输入/输出要求: Input: [[h,i],[h,e,l,l,o],[l,a,p,t,o,p]] 只是我需要摆脱那些,: Expected output: [hi, hello, laptop]. 我的代码: make_LoL([],Res). make_LoL([H|T],Res) :- atom_con(H,Out), newRes = [Out|Res], make_LoL(T,newRes). atom_con([],Out). at

请遵循输入/输出要求:

Input:    
[[h,i],[h,e,l,l,o],[l,a,p,t,o,p]]
只是我需要摆脱那些

Expected output: 
[hi, hello, laptop].
我的代码:

make_LoL([],Res).
make_LoL([H|T],Res) :-  
    atom_con(H,Out),
    newRes = [Out|Res], 
    make_LoL(T,newRes).

atom_con([],Out).
atom_con([H1,H2,H3|T],Out) :-
    atom_concat(H1,H2,Ou),
    atom_concat(Ou,H3,Out),
    atom_con([], Out).
当我运行它时,它会永远循环。知道我做错了什么吗?

看看这是否有效:

string([], []).
string([H | T], [S | Z]) :- helper(H, S), string(T, Z).

helper([A], A).
helper([H | T], S) :- helper(T, Z), atom_concat(H, -, Z1), atom_concat(Z1, Z, S).  

若子列表为空,则模式匹配将失败,结果将为false。因此,此解决方案仅在每个子列表包含至少一个字符时有效

简短回答:
maplist(原子字符,如,[[h,i],[h,e,l,l,o],[l,a,p,t,o,p]])。
。。。不,我不能观察到一个循环——而是你的大脑中的一个失败code@false很酷,谢谢。@false我很好奇,我如何在两个字符之间添加破折号,例如
[[h-I,h-e-l-l-o],[l-a-p-t-o-p]]
?你从哪里得到那个代表?我很怀疑你的意思是
nil-h-I
等等