Re: Converting Scheme to Prolog
- From: Matthew Huntbach <mmh@xxxxxxxxxxxxxx>
- Date: Mon, 8 Oct 2007 09:45:44 +0100
On Sat, 6 Oct 2007, Pierpaolo BERNARDI wrote:
On Sat, 06 Oct 2007 17:58:08 +0200, Daemon <kewldaemon@xxxxxxxxx> wrote:
What I'm trying to figure out is, how can I make it return;
L = [[a, b, c, d][a, b, c, e][a, b, d, e]a, c, d, e][b, c, d, e]]
use findall.
There is no need to use findall. As ever, the problem here comes
from trying to save information over backtracking, which can't easily
be done in Prolog. But then you don't have to use backtracking for this
problem, just think logically and recursively with lists.
I haven't even tried to code it up, but here's how I start thinking
about it.
We have ncombs(N,L1,L2)
where we want L2 to be all combinations of length N from L1 which
preserve the order of their elements from L1.
Well, thinking recursively, all the combinations must come from two
sublists which can be appended together:
all combinations of length N preserving the order from the tail of L1
all combinations of length N-1 preserving the order from the tail of
L1 with the head of L1 consed to the front of each.
Also we have all combinations of length 0 from any list is [[]] i.e.
there is one combination which fits, the empty list, and we are
returning a list of lists. Plus there are no combinations of length
greater than 0 from the empty list, so in this case return [].
This should translate naturally to a Prolog program.
Matthew Huntbach
.
- References:
- Converting Scheme to Prolog
- From: Daemon
- Re: Converting Scheme to Prolog
- From: Pierpaolo BERNARDI
- Re: Converting Scheme to Prolog
- From: Daemon
- Re: Converting Scheme to Prolog
- From: pineapple . link
- Re: Converting Scheme to Prolog
- From: pineapple . link
- Re: Converting Scheme to Prolog
- From: Daemon
- Re: Converting Scheme to Prolog
- From: Matthew Huntbach
- Re: Converting Scheme to Prolog
- From: pineapple . link
- Re: Converting Scheme to Prolog
- From: Chip Eastham
- Re: Converting Scheme to Prolog
- From: Pierpaolo BERNARDI
- Re: Converting Scheme to Prolog
- From: Jan Wielemaker
- Re: Converting Scheme to Prolog
- From: Daemon
- Re: Converting Scheme to Prolog
- From: Pierpaolo BERNARDI
- Converting Scheme to Prolog
- Prev by Date: Re: Compiling with gnu-prolog???
- Next by Date: Re: Planner, micro-planner, etc.
- Previous by thread: Re: Converting Scheme to Prolog
- Next by thread: Re: Converting Scheme to Prolog
- Index(es):
Relevant Pages
|