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

From: Markus Triska (triska_at_gmx.at)
Date: 12/01/04


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.



Relevant Pages

  • Re: An instance of Russells paradox?
    ... >>infinite generalization of the arity of every predicate (I got this ... the representation ... > of lists is actually syntactic sugar for the binary term ... notation, the list notation, and the operator notation. ...
    (sci.logic)
  • help with parsing and dcg (swi-prolog in particular)
    ... I converted the lisp lists to prolog lists wrapped in a predicate and ... The parser read in the file char by char and wrote char by char. ... I was wondering about using DCG to parse the file. ...
    (comp.lang.prolog)
  • Re: Something I dont understand about macros and special operators
    ... which looks for these patterns and provides an alternate text rendering ... notation, and so it is printed plainly. ... For instance try these (I'm trying them on CLISP 2.33): ... So there is no reason to read and write lists ...
    (comp.lang.lisp)
  • Re: backtracking in prolog
    ... The predicate is called foo for example (so foo takes two ... that does not satisfy the given predicate. ... backtracking, ... expect to happen for various lists that have more than ...
    (comp.lang.prolog)
  • Re: backtracking in prolog
    ... The predicate is called foo for example (so foo takes two ... that does not satisfy the given predicate. ... backtracking, ... expect to happen for various lists that have more than ...
    (comp.lang.prolog)