[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is GNU Prolog interpreter output missing quotes for '<>', '[]', and

From: Salvador Abreu
Subject: Re: Is GNU Prolog interpreter output missing quotes for '<>', '[]', and '{}'?
Date: Fri, 27 Jan 2012 07:47:42 +0000


On Jan 27, 2012, at 05:45, Dave Sworin wrote:

> In gprolog 1.3.1 and gprolog 1.4.0 the following occurs.
> A = []
> The same is true for '{}' and '<>'.  However, '()' works as I expected.
> If a term includes the atom '[]', the term displays an empty list instead of 
> an atom.
> A = f(abc,1.25,'[]').[ENTER KEY PRESSED]
> A = f(abc,1.25,[])
> So the term now contains an empty list.

The empty list is, by definition, the atom '[]' (which is the *same thing* as 
just [], without the quotes).

>  This seems so very minor but when I copy GNU Prolog output
> from the interpreter display and paste it back into the interpreter
> for another query, the term is incorrect and the query fails.
> I encountered this when writing code which outputs some Prolog source code
> as in a small code generator for a repetitive task.

If you want to write something that can be read back in (or pasted into the 
top-level) you want to use writeq/1 or write_canonical/1.  Typically you would 

        ...make term X...
        writeq(X), write(.), nl,
        ...keep going...

whatever is written may (normally) get read back in (or copy-pasted).

another possibility is to use format/2, as in:

        ...make X...
        format("~q.~n", [X]),

> Is this a bug???

No. :-)

Salvador Abreu       --  http://www.di.uevora.pt/~spa/
Departamento de Informatica
Universidade de Evora - PORTUGAL

reply via email to

[Prev in Thread] Current Thread [Next in Thread]