3 Replies - 275 Views - Last Post: 26 November 2013 - 07:43 PM Rate Topic: -----

#1 Ap0C552  Icon User is offline

  • D.I.C Regular

Reputation: -7
  • View blog
  • Posts: 319
  • Joined: 08-December 10

Prolog return problem

Posted 26 November 2013 - 02:12 PM

I am having a problem, and I am not sure if it might be with the IDE.

I am using Amzi prolog 6.

I have a member predicate, and I want it to return all possible members of a list.

member(X,[1,2,3]).

X=1
X=2
X=3

But for some reason when I try it, it only returns X=1.

I have tried it with three different approaches to the code, and they are all the same result.

%member(X,[X|T]).
% ver 1
member(X,[H|T]) :- member(X,T).


% ver 2
member(X, [Y|T]) :- X = Y; member(X, T).

% ver 3
member(X,[X|R]).
member(X,[Y|R]) :- member(X,R).


Is This A Good Question/Topic? 0
  • +

Replies To: Prolog return problem

#2 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Prolog return problem

Posted 26 November 2013 - 05:33 PM

The second and third ones should work, the first one will always return false. Remember when testing a predicate to use ; to output all results.
Was This Post Helpful? 0
  • +
  • -

#3 Ap0C552  Icon User is offline

  • D.I.C Regular

Reputation: -7
  • View blog
  • Posts: 319
  • Joined: 08-December 10

Re: Prolog return problem

Posted 26 November 2013 - 06:40 PM

Ya the problem is, the second and third ones don't work. So am I doing something wrong in the listener? Or is something wrong with my listener or ide?
Was This Post Helpful? 0
  • +
  • -

#4 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Prolog return problem

Posted 26 November 2013 - 07:43 PM

You are probably doing something wrong in the listener.
> member(X, [1, 2, 3, 4]).
X = 1 ;
X = 2 ;
X = 3 ;
X = 4 ;
no


The ; that you see is what you type in the listener to tell the system that you'd like to see more solutions to the problem, if there are no more solutions, no is printed.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1