Prolog Type Error

前端 未结 4 890
面向向阳花
面向向阳花 2021-01-27 07:23

I\'m working on a prolog algorithm that will perform a \"swap\" on a list.

Example:

Input: [1,2,3,4] -> Output: [3,4,1,2] Input: [1,2,3,4,5] -> Output: [4,5,3,1

4条回答
  •  无人共我
    2021-01-27 07:33

    round is not a function, it's a predicate. I haven't looked at the rest of the code, but that line should be

    round(Length/2, R), trim(L, R, A)
    

    EDIT: BTW, you're overthinking it.

    swap([], []).
    swap([X], [X]).
    swap([X, Y | A], [Y, X | B]) :- swap(A, B).
    

提交回复
热议问题