Page 1 of 1

Prolog - findall

Posted: Tue Mar 15, 2005 9:39 am
by jelleghys
Hello,

I'm having some trouble in Prolog (SWI). If I would do this:

Code: Select all

?- findall(A-B,append(A,B,[1,2,3]),L).
I would get this:

Code: Select all

L = [[] - [1,2,3],[1] - [2,3],[1,2] - [3],[1,2,3] - []]
But then, how can I, for example, check what the value of the last element of the first list from each of these elements in L is. What I mean is this:

[] - [1,2,3] -> no (or whatever)
[1] - [2,3] -> 1
[1,2] - [3] -> 2
[1,2,3] - [] -> 3


Thanks in advance.

Re:Prolog - findall

Posted: Thu Apr 07, 2005 7:06 am
by DevL
I guess there are few Prolog programmers around here and I'm a bit short on time and memory of Prolog myself (has been a few years since I last did some AI-related work in Prolog).

However, if you're still interested I can have a go at cracking this nut during the weekend. So, no promises, but I'll take a shot at it unless you've already found the solution (if you have, please post it here and in any other forums that you've asked this - this goes for everyone else and for every type of question by the way).

Cheers!

Re:Prolog - findall

Posted: Thu Apr 07, 2005 7:14 am
by DevL
You might be able to use ?- takeout or ?- member to achieve what you want.

http://www.intranet.csupomona.edu/~jrfi ... l/2_7.html

Re:Prolog - findall

Posted: Thu Apr 07, 2005 7:17 am
by jelleghys
Well, I still don't know how to do it, but I've worked around the problem. So, you shouldn't waste you time on it. Of course, you may if you really want to, but i'm probably not going to use it.

Thanks anyway!

-jelle

Re:Prolog - findall

Posted: Thu Apr 07, 2005 7:52 am
by DevL
Okay, no problem then. :-)