Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7163847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:58:16+00:00 2026-05-28T13:58:16+00:00

In a prolog program as stated below: town(a). town(b). town(c). town(d). dam(e). dam(f). link(a,b).

  • 0

In a prolog program as stated below:

town(a).
town(b).
town(c).
town(d).
dam(e).
dam(f).
link(a,b).
link(a,c).
link(c,d).
link(b,d).
link(b,c).
link(c,e).
link(a,e).
link(d,f).
neighbour(X,Y):- link(X,Y) ; link(Y,X).

Would this be the correct procedure all_neighbours(L,X) which returns a list L of all neighbouring towns to X: all_neighbours(L,X):- town(Y), findall(Y, neighbour(X,Y), L).

Would this be the correct procedure has_dam(L) which returns a list L of all towns that have at least one neighbouring dam: has_dam(L):- dam(Y), town(X), findall(X, neighbour(X,Y), L).

Would this be the correct procedure no_dam(L) which returns a list L of all towns that have no neighbouring dam: no_dam(L):- town(X), not dam(Y), findall(X, neighbour(X,Y), L).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:58:17+00:00Added an answer on May 28, 2026 at 1:58 pm

    Nope, none of these are correct. In the first, the call to town should be done within the scope of the findall:

    all_neighbours(Neighbourhood, X) :-
        findall(Y, (town(Y), neighbour(X, Y)), Neighbourhood).
    

    and similarly for the rest. Note the parentheses around the second argument to findall. These are required, since

    findall(Y, town(Y), neighbour(X, Y), Neighbourhood)
    

    would be parsed as a call to (the probably non-existant) findall/4.

    To understand the findall query, spell it out:

    Find all Y such that (Y is a town and X neighbours Y) and call the result Neighbourhood.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote this simple Prolog program. man(socrates). mortal(X) :- man(X). immortal(X) :- immortal(X). I
I have this program in Prolog, it removes elements at each nth element from
I'm trying to make program in prolog that will do something like this: diffSet([a,b,c,d],
I want to program this algorithms in Prolog, and first I need to create
I'm new to Prolog. Using this basic 'database' structure, I thought I would be
I was trying this palindrome program in prolog, the logic works but write operation
in visual prolog there is domains section in a prolog program in which you
I have a large Prolog program with lots of predicates. I need to connect
Upon loading into a C++ program a Prolog program that contains the command 'send'
I am writing a Prolog program to solve a problem. The problem takes three

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.