Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.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
List Prolog-要列出的矩阵_List_Recursion_Matrix_Prolog - Fatal编程技术网

List Prolog-要列出的矩阵

List Prolog-要列出的矩阵,list,recursion,matrix,prolog,List,Recursion,Matrix,Prolog,这里有一个将列表(任意长度)转换为矩阵的问题(请参见底部的链接),但我想做相反的事情,递归地将矩阵转换为列表 Matrix = [[a,b,c],[d,e,f]] 定义谓词: matrixToList(MyMatrix,NewList) 其中NewList=[a,b,c,d,e,f]。 有人能帮忙吗? 多谢各位 这是我针对同一问题的代码,但是是的,您也可以使用flatte getAllElements([],[]). getAllElements([H|T], ElementsList) :

这里有一个将列表(任意长度)转换为矩阵的问题(请参见底部的链接),但我想做相反的事情,递归地将矩阵转换为列表

Matrix = [[a,b,c],[d,e,f]]
定义谓词:

matrixToList(MyMatrix,NewList)
其中
NewList=[a,b,c,d,e,f]。

有人能帮忙吗?
多谢各位


这是我针对同一问题的代码,但是是的,您也可以使用flatte

getAllElements([],[]).
getAllElements([H|T], ElementsList) :- getAllElements(T, NewElementsList),
                                       append(NewElementsList, H, ElementsList).

你能列举一下吗?我想知道,现在所有的Prolog课程都在教授和推广使用驼峰格来表示Prolog函子的名字吗?正如@aBathologist所建议的,
matrix-to-list(MyMatrix,NewList):-flatten(MyMatrix,NewList)。
将是最干净的实现。@mbrach我认为这不是故意的,很可能是Java编程的习惯。如果您遵循这里很好地描述的编码约定:那么它也将是
My_Matrix
甚至
My_Matrix
@aBathologist:使用
flatten/2
绝对是个坏主意:整数矩阵的矩阵将因此被展平为整数列表,而不是整数矩阵列表。请参阅