Re: Prolog newbie stuck at Monkey World (lists, adding, etc.)

From: Peter Ludemann (peter.ludemann_at_gmail.com)
Date: 12/01/04


Date: 30 Nov 2004 20:24:47 -0800

Markus Triska <triska@gmx.at> wrote in message news:<41ab9d1b$0$11094$3b214f66@tunews.univie.ac.at>...
> Emre Sevinc wrote:
>
> >
> > canget( state( _, _, _, has), Actions ).
> > canget( State1, Actions) :-
> > move( State1, Move, State2),
> > Actions1 = [Move|Actions],
> > canget( State2, Actions1).

DCG notation is your friend - efficient (uses difference lists behind
the scenes), less typing, and it produces the Actions in order.

canget(state(_,_,_,has)) --> [].
canget(State1) -->
    { move(State1, Move, State2) },
    [Move],
    canget(State2).

For a bit more detail, look for my posting "Re: expand_answer -- how
to use??" 2004-11-19 04:34:35 PST ... or read any good Prolog text.

Peter van Roy's, EDCG notation may be even better for this -- it
allows multiple accumulators.
http://www.info.ucl.ac.be/people/PVR/edcg.html