Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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 如何在列表头之前将规则应用于列表?_List_Prolog - Fatal编程技术网

List 如何在列表头之前将规则应用于列表?

List 如何在列表头之前将规则应用于列表?,list,prolog,List,Prolog,我在此表格中有一套规则: regla(o,o,o,o). 语句(这是家庭作业)的编写方式,我有一个列表作为输入,我必须在列表开始之前应用规则2个元素(这是可能的,因为据说列表开始之前和之后都有无限的符号,都是一样的) 现在,我的问题是,我无法想出一种方法来操作整个列表 也就是说,我的想法是对列表的头部进行一个操作,然后递归到列表的主体,最后对列表的尾部进行另一个操作 类似这样的东西(不幸的是,它还不起作用): 在没有这么多子案例的情况下,是否有一些方法可以做到这一点?我无法摆脱这种感觉,我正在

我在此表格中有一套规则:

regla(o,o,o,o).
语句(这是家庭作业)的编写方式,我有一个列表作为输入,我必须在列表开始之前应用规则2个元素(这是可能的,因为据说列表开始之前和之后都有无限的符号,都是一样的)

现在,我的问题是,我无法想出一种方法来操作整个列表

也就是说,我的想法是对列表的头部进行一个操作,然后递归到列表的主体,最后对列表的尾部进行另一个操作

类似这样的东西(不幸的是,它还不起作用):

在没有这么多子案例的情况下,是否有一些方法可以做到这一点?我无法摆脱这种感觉,我正在使它变得比需要的更困难

作为参考,输入类似于OXO,正如我所说的,假设之前和之后的一切都是o

提前谢谢,很抱歉我的问题结构不好,我没有足够的词汇来正确地“称呼”这个问题

:- ensure_loaded('automaton.pl').

listsplit([H1,H2,H3|T], H1,H2,H3, T).


%regla(o,o,H1,Output).**This would be the operation to the head of the list**


%append(Output,Accumulator).%we manually add the first and last elements of the list
%cells(InList,OutList). Caso Base:
%cells( [ ], _).%perhaps cells( [ ], []). would be less dangerous


cells(Input, Result):-cellsAUX(Input, Accumulator, Result).%base case removed because examples use it in the equivalent to  the cellsAUX call

cellsAUX([], Result, Result).
cellsAUX(Input, Accumulator, Result):-**This would be the operations to the body of the list, calling itself recursively, and adding the results of each iteration to an Accumulator**
            listsplit(Input,Head1Arg1,Head2Arg1,Head3Arg1,T),
            regla(Head1Arg1,Head2Arg1,Head3Arg1,Output),
            cellsAUX([Head2Arg1,Head3Arg1|T] , [Output|Accumulator], Result).