Re: Prolog newbie stuck at Monkey World (lists, adding, etc.)
From: Markus Triska (triska_at_gmx.at)
Date: 12/01/04
- Next message: Nick Wedd: "Re: cut in SWI-Prolog"
- Previous message: Nick Wedd: "Re: Beginners Question"
- In reply to: Peter Ludemann: "Re: Prolog newbie stuck at Monkey World (lists, adding, etc.)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 01 Dec 2004 14:38:14 +0100
Peter Ludemann wrote:
> DCG notation is your friend - efficient (uses difference lists behind
> the scenes), less typing, and it produces the Actions in order.
I agree that your solution is better. However, I don't know if the OP
has learned about DCGs already. From my experience, I can only heartily
recommend to stick to conventional predicate notation until you have
mastered the basics and understand difference lists. Then, you can try
out DCG notation.
Also note that I was explaining a concrete question of the OP, namely
why his predicate (where he inserted new moves at the beginning of the
supposed result list) failed, and I therefore kept the structure of his
original program: Especially beginners should know that the DCG you give
is *not* the notational equivalent of my rewritten conventional
predicate. A DCG works quite the other way around, i.e., it does not
start from the empty list and accumulates the moves, but starts with a
free list, unifies more and more, and the rest ("list difference") must
be nil. As you say, this has the advantage that moves remain in correct
order.
Markus.
- Next message: Nick Wedd: "Re: cut in SWI-Prolog"
- Previous message: Nick Wedd: "Re: Beginners Question"
- In reply to: Peter Ludemann: "Re: Prolog newbie stuck at Monkey World (lists, adding, etc.)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|