ARTI/CSCI-4540/6540
Cool List Assignment 1
Here are some fun predicates for
you to play with. Look them over and
let’s discuss any questions you have on Tuesday. Let’s set the target due date to next
Thursday (20th) but we might extend that based on the discussion
Tuesday.
cool_reverse(+List, -Result) reverses a list that possibly contains sub lists and
reverses the elements in the sub lists also; keeping the “structure” of the
list intact. cool_reverse([a,[b,c],d],
X) gives X = [d,[c,b],a].
cool_delete_all(+Ele, +List, -Result) deletes all Ele from List and any sub lists contained
within List. cool_delete_all(c,
[a,[b,c],d], X) gives X = [a,[b],d].
flat_reverse(+List, -Result) flattens and reverses List. Ideally, you should do this the customized
way and not simply use “flatten” and then “reverse”.
flat_delete_all(+Ele, +List, -Result) flattens List and deletes all occurrences of
Ele. Ideally, you should do this the
customized way and not simply use “flatten” and then “delete_all”. Caution: think about this a moment and see if
you realize the “problem” that might arise if Ele is
a list. Right, if you flatten List
first, then there won’t be any Ele occurring in the
flattened list.
perms(+List, -Result) takes a List of elements and prepares a Result list
containing sub lists that correspond to the permutations of List. For example, perms([a,b], X) gives X =
[[a,b], [b,a]]. Not necessarily in that
order.
power(+List, -Result) takes a List of elements and prepares a Result list
containing sub lists that correspond to the “subsets” of List. For example, power([a,b], X) gives X = [[],
[a], [b], [a,b]]. Not necessarily in
that order.