Edit this page Backlinks This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== Generative predicates ====== 1. Write the predicate ''sublist/2'' which constructs **each** sublist of a given list. Hint: use ''append''. <code> ?- sublist([7,2,9],R). % R will subsequently be bound to [], [7], [2], [9], [7,2], [2,9], [7,2,9] </code> 2. Rewrite the predicate such that the empty list is reported only once. 3. Write the predicate ''natlist/1'' which generates **each** finite list of natural number in ascending order. <code> ?- natlist(R). R = [0] ; R = [0,1] ; R = [0,1,2] ; ... </code> 4. Write the predicate ''oddOnly/2'' which removes all even integers from a list. <code> ?- oddOnly([1,2,3,4],R). R = [2,4]. </code> 5. Write the predicate ''oddList/1'' which generates all finite lists of odd numbers, in ascending order. 6. Write a predicate ''eqelem/1'' which generates all lists of **uninstantiated** variables which must be equal. Example: <code> ?- eqelem(L), length(L,3), L=[0|_]. L = [0,0,0]. </code> 7. Use the previous predicate to write ''repeat/3'' which returns a list containing the same value ''X'' repeated ''K'' times. 8. Write a function ''pal/1'' which generates **all** lists of palindroms. Hint: use only ''append''. 9.