Jump to content


Basic prolog help please!!


3 replies to this topic

#1 scampno2

    New Member

  • Members
  • Pip
  • 2 posts

Posted 28 October 2005 - 11:34 AM

I am really struggling with finding the solutions to the following prolog questions....any help would be greatly appreciated:

1)street_address/2 takes the full name of an individual (arguments 1&2) and prints their street address to the screen. The rule should output a suitable message if the specified user does not exist...

i can get the first bit ok, but unsure of how to output the messgae if the user doesnt exist. the output is supposed to be similar to below:

e.g.
?- street_address(bloggs,fred).
22 york street

?- street_address(mojo,jojo).
No such person


2) neighbours/4 finds a pair of names (arg 1&2) and the addresses (arg 3&4) of any individuals who live next door to one another (i.e. live on same street and their house numbers differ exactly by 2).... i can get the first bit again but have no idea how to compare the addresses to get something similar to the following output..



?- neighbours(N1,N2,S1,S2).
N1 = name(brown,jack)
N2 = name(black,jack)
S1 = street(9,castlerock,road)
S2 = street(11,castlerock,road)

HELP please!!!

#2 dave_

    Senior Member

  • Members
  • PipPipPipPip
  • 584 posts

Posted 28 October 2005 - 03:38 PM

Ask your teacher! I dont think you're supposed to be posting homework questions here

#3 scampno2

    New Member

  • Members
  • Pip
  • 2 posts

Posted 02 November 2005 - 11:36 AM

Thanks for that but unfortunately it is a self taught module.... any pointers in the right direction would be greatly appreciated.

#4 Ed Mack

    Senior Member

  • Members
  • PipPipPipPip
  • 1239 posts

Posted 02 November 2005 - 02:55 PM

This is of course not proper syntax - there are so many implimentations, that's your problem :D

For the first one, you could create a street_address rule at the end, to catch unfound references:

street_address (A,B)
print "Not found"

For the neighbours bit:

neighbours (N1, N2, S1, S2)
S1 = street (N, R1, R2)
S2 = street (N+2, R1, R2)

Your syntax is really different from mine, so getting the names bit is for you to do as I'm unsure what I can and cannot do.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users