Prolog - findall

Programming, for all ages and all languages.
Post Reply
jelleghys

Prolog - findall

Post 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.
DevL

Re:Prolog - findall

Post 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!
DevL

Re:Prolog - findall

Post 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
jelleghys

Re:Prolog - findall

Post 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
DevL

Re:Prolog - findall

Post by DevL »

Okay, no problem then. :-)
Post Reply