combinations of variable length nested lists

Alex Martelli aleax at aleax.it
Wed Aug 8 08:11:56 EDT 2001


"Joseph A. Knapka" <jknapka at earthlink.net> wrote in message
news:3B7060B7.1D63A71D at earthlink.net...
    ...
> > > > one_of_each([],[]).
> > > > one_of_each([H|T],[H1|Ts]) :- member(H1,H), one_of_each(T,Ts).
> >     ...
> > > backtracking Horn-clause resolution engine, that can't be real
> > > terminology, I am sure you just plagerised Elmer Fudge :)
> >
> > The terminology is right, but the Prolog example he gives looks
> > just like a transliteration of a ML or Haskell program and uses no
> > backtracking that I can see.
>
> Yet it's there. member/2 is nondeterministic, so the code
> above will find every solution, if invoked via findall or
> within a failure loop.

Sorry, you're right: this doesn't *use* backtracking itself,
but it does *support* it (as it contains no cuts), so a
findall, or failures in other clauses using this definition
of one_of_each, will indeed make it exhaust all the various
possibilities.


> I don't know ML or Haskell (yet :-)

They don't do implicit backtracking.  But I think there
are now languages which do support both the backtracking/
logic programming/unification aspects AND the functional
programming approach that ML and Haskell emphasize so
well (particularly the latter, with its default to lazy
evaluation and immutability) -- no direct experience,
but I'm told both Mercury and Mozart are worth checking
out if you're into such stuff (I would be, but finding
the time for it is another issue:-).


Alex






More information about the Python-list mailing list