Cuts
- Due:
- 5:00am, Wednesday November 13, 2024
Description
Write a Prolog file named p4.pl
that defines the following predicates:
remove(Element, InList, OutList)
– remove the first occurrence ofElement
fromInList
. IfElement
does not occur inInList
, then return the original list.add(Element, InList, OutList)
– AddElement
toInList
only if it does not yet exist inInList
. That is, there should be no duplicates in theOutList
.notmember(Element, List)
– Use the cut and fail predicates to return true ifElement
is not a member ofList
and false otherwise.sum(List, Result)
– sum the elements of the list according to the following rules:- If the element is an integer, then add it to the sum.
- If the element is an atom, then add 1 to the sum.
- If the element is a floating point number, then add -1 to the sum.
- Otherwise, add 0 to the sum.
Make a tail recursive version of the following predicate:
max([H], H). max([H|T], Max) :- max(T, Max1), (H >= Max1, !, Max = H ; Max = Max1).
Turning in the Assignment
To submit your assignment, create a zip file named p4.zip
of a
DIRECTORY named p4
containing the following files:
p4.pl
Then submit that file to the appropriate folder on D2L.