bug-prolog
[Top][All Lists]
Advanced

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

Re: 'mod' and 'div' need brackets ro read as atoms


From: Daniel Diaz
Subject: Re: 'mod' and 'div' need brackets ro read as atoms
Date: Fri, 5 Aug 2011 11:35:23 +0200


Le 5 août 2011 à 09:25, Jasper Taylor a écrit :

Sorry, I still don't understand.

OK, I see 'div' and 'mod' are infix operators,
(BTW the document you referenced makes no mention of 'mod'), but...

mod/2 is already defined in the initial ISO reference. DTC2 is a corrigendum and thus does not redefine all operators.



Why does this prevent them being read as atoms in GNU-prolog?
(It works in other Prologs that also have them as infix operators)

They can be read as atoms but they need to be bracketed. In the presence of 2 infix operators ISO Prolog requires that the one which is the argument of the other (the real operator) be bracketed. This is to avoid misinterpretation. 

Examples:

X = foo. is OK because foo is not an operator. foo is an atom. X = (foo). is also OK (but not mandatory). foo is read as an atom.

X = + is not OK because + is an operator. X = (+). is OK and + is read as an atom.

Similarly, X = div is not OK because div is now an operator. X = (div) is OK and div is read as an atom.


Is it therefore a bad idea to save application data as Prolog terms, given that changes to the standard may have the effect that future Prolog systems are unable to read them?

If this is really an issue, the best solutions consists in using write_canonical which ensures the emitted term can be read back with read/1 (for this, write_canonical does not use operators).

Daniel


    --Jasper

On 05/08/11 07:53, Daniel Diaz wrote:
hello Jasper,

gprolog 1.4.0 follows the "next" Prolog ISO standard (which is in fact a corrigenum) called DTC2


in which div is an operator (flooring integer division). As an argument of an operator you have to write (div). E.g. instead of P = div you have to write P = (div). This is compatible with older versions of gprolog.

Daniel


Le 4 août 2011 à 18:50, Jasper Taylor a écrit :

| ?- P = div.
uncaught exception: error(syntax_error('user_input:1 (char:5) current or previous operator needs brackets'),read_term/3)

This is a problem because I cannot read terms written by pre-1.4 versions of GNU prolog (or other prologs) including these atoms. Also there does not seem to be any reason for it -- other 2-ary arithmetic operators like atan2 can be read directly so why not these?
   --Jasper


_______________________________________________
Bug-prolog mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/bug-prolog

--
Ce message a ete verifie par MailScanner
pour des virus ou des polluriels et rien de
suspect n'a ete trouve.



--
Ce message a été vérifié par MailScanner pour des virus ou des polluriels et rien de suspect n'a été trouvé.


--
Ce message a été vérifié par MailScanner pour des virus ou des polluriels et rien de suspect n'a été trouvé.
_______________________________________________
Bug-prolog mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/bug-prolog


--
Ce message a été vérifié par MailScanner pour des virus ou des polluriels et rien de suspect n'a été trouvé.

reply via email to

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