Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!apple!olivea!samsung!munnari.oz.au!lee From: lee@munnari.oz.au (Lee Naish) Newsgroups: comp.lang.prolog Subject: Re: Standards question: behavior of arg/3 Keywords: ANSI, standard Message-ID: <5816@munnari.oz.au> Date: 19 Oct 90 08:57:49 GMT References: <9888@bunny.GTE.COM> <3992@goanna.cs.rmit.oz.au> <1920@tuvie> <4018@goanna.cs.rmit.oz.au> Sender: news@cs.mu.oz.au Reply-To: lee@munmurra.UUCP (Lee Naish) Organization: Comp Sci, University of Melbourne Lines: 52 > > ?- arg(N, [a,b,c], X). > >makes perfect sense and has two solutions > > N = 1, X = a ; > > N = 2, X = [b,c] . > > Which Prolog systems have arg/3 defined in this way? MU-Prolog 3.2db 1?- arg(N, [a,b,c], X). N = 1, X = a ; N = 2, X = [b, c] ; fail. 2?- As Richard pointed out, NU-Prolog delays this goal. NU-Prolog is a WAM based system and open codes arg/3 - it knows it is deterministic. MU-Prolog is an interpreter (the implementation of arg/3 is particularly inefficient - I put in a quick hack and never got around to doing it properly, but MU-Prolog isn't a really "serious" Prolog system anyway). Richard also mentioned Sicstus failing with this goal. I think its unfortunate that Sicstus does not make more of its coroutining facilities. There lots of builtins which could be made to behave more logically using these facilities. One possible reason for not doing this is to remain compatible with various other Prolog systems which fail silently. There is something to be said for this. I have had the "pleasure" of porting a 30,000 line program written in (an old version of) Quintus Prolog to NU-Prolog. One of the nastiest bugs was a call to functor/3 which failed in Quintus because it was insuffiiently instantiated, but delayed in NU-Prolog. I'm not sure what the latest version of Quintus does. I hope more systems start producing error messages in situations like this (you can always add a call to nonvar/1 if you really want failure). Another way of solving the porting problem is to support two versions of functor, arg, is, <, etc, etc, as IBM Prolog does. You should definitely do this for some builtins, such as the type tests (integer etc). However, I think Prolog vendors would be doing every?one a favour if they made functor etc produce error messages when insufficiently instantiated. I don't think it would hurt to put this into the standard(s) either, even though most existing systems would not conform. I haven't seen any recent draft standards - do they discuss the general class of errors called instantiation faults? Richard's 1984 draft did. lee