bug-prolog
[Top][All Lists]
Advanced

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

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


From: Dave Sworin
Subject: Re: Is GNU Prolog interpreter output missing quotes for '<>', '[]', and '{}'?
Date: Mon, 30 Jan 2012 08:39:15 -0800 (PST)

Thank you.  This possibility did not occur to me.
 
| ?- list([]),atom([]).
 
yes
| ?-
 
Dave
From: Salvador Abreu <address@hidden>
To: Dave Sworin <address@hidden>
Cc: address@hidden
Sent: Friday, January 27, 2012 1:47 AM
Subject: Re: Is GNU Prolog interpreter output missing quotes for '<>', '[]', and '{}'?

Hi,

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

> In gprolog 1.3.1 and gprolog 1.4.0 the following occurs.

> A = '[]'.[ENTER KEY PRESSED]
> 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 use

    ...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. :-)

regards,
--
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]