Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating binary predicates

Status
Not open for further replies.

gopi29

Technical User
Nov 7, 2006
1
US
Can you guyz help me out in answering the following question?
Create a binary predicate called 'square' which will square each
number in a list. This pred. will be shallow.
e.g. ?-square([a,[[3]],b,4,c(5),8],X).
X=[a,[[3]],b,16,c(5),64]

2. Create a binary predicate called 'deepsquare' which will give
a list in which all numbers are squared, including those in sublists.

e.g. ?-dcountSublists([a,[[3]],b,4,c(5),4],C).
C=[a,[[9]],b,c(5),16]


3. Write a predicate 'addbubba' which will place 'bubba' after each atom in a
list. The empty list is unchanged.

e.g. ?-addbubba([a,b,8,c],X).
X=[a,bubba,b,bubba,8,c,bubba]

This one is shallow, not deep.

4. Write a predicate 'everyother' which will remove every other element in a list,
starting with the second element. List length can be odd or even.

e.g. ?- everyother([g,r,o,u,l,l,o,e,r,s,p],L).
L = [g,o,l,o,r,p];
fail
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top