Prolog, building list with conditional clauses

前端 未结 4 1030
南旧
南旧 2021-01-12 02:46

I need to do this homework assignment using prolog (SWI-flavor) and cant get my head around some things.

For example, if i want to iterate through a list and add it

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-12 03:00

    try the ignore/1 predicate:

    goal(Stuff) :-
        do_something(X)
        ignore(only_do_this_if_something(Y)),
        always_do_this(Z).
    

    ignore/1 calls the only argument and succeeds whenever it fails or not:

    ignore(X) :- X, !.
    ignore(_).
    

提交回复
热议问题