Article View: comp.lang.prolog
Article #1302Re: Standards question: behavior of arg/3
From: Peter G Ludemann
Date: Mon, 22 Oct 1990 18:36
Date: Mon, 22 Oct 1990 18:36
59 lines
3149 bytes
3149 bytes
| > Richard might not like the fact that IBM's arg/3 allows
| > arg(0,f(a),f) -- that's easily fixed by using a delayed inequality:
| > wait:(N ==/ 0) & arg(N,F,X)
|
| Ah, I see: if N is already instantiated the N==/0 (what the dickens
| does ==/ mean?) goal will fail, ...
'==/' is IBM-Prolog-ese for not equal, treating varaibles as distinct.
I put the ==/ inside wait:(...) so that the test will delay until
everything is instantiated (by the way, Richard, this is all in
the manual which I sent you). Of course, I could have been less
fancy and simply done:
arg(N,F,X) & N =/ 0
('=/' is the usual inequality.) It all depends whether you think that
N will usually be instantiated or not, so pick one goal ordering or
or the other, to get the most efficient execution.
The "priority prefix" technique of designating which predicate
should be used is a very powerful technique. For example, suppose
that I wanted arg/3 to generate an error whenever the N was not
ground to an integer. I could program this:
my:arg(N,F,X) :- is_not_ground_int(N), !, error(...) .
my:arg(N,F,X) :- built2:arg(N,F,X) .
and declare that 'my' is the prefix to use whenever arg/3 is
encountered (by default, 'built' or 'built2' would be used).
In this way, I can trivially get the semantics I want without
having to read through 30,000 lines of source.
Richard and I had a long discussion about arg/3 vs arg0/3. I think
that I can summarize it as follows:
- Edinburgh treats functor names as special and doesn't allow
input like "f()". For Edinburgh compatibility, arg(0,...)
should fail.
- Prolog-II, Prolog-III, IBM-Prolog (and others?) have a more
generalized view of functors. For example, using this view,
one could define =../2 by the infinite list of clauses:
F =.. [F] .
F() =.. [F] .
F(A) =.. [F,A] .
F(A,B) =.. [F,A,B] .
etc.
Furthermore, a principal functor is not limited to be an atom;
it can be any term. Using the syntax <<f(a),2,3>>, the principal
functor is itself a functor: f(a).
Of course, this extended view is *not* Edinburgh Prolog
(which also doesn't properly support the "infinite rational
trees" of Prolog-II and IBM-Prolog); and there is no particular
reason for ISO to support this extension to functors -- and every
Prolog which claims to be Edinburgh compatible should support the
original Edinburgh design (whether or not ISO should support the
original Edinburgh design is an entirely different issue).
- peter ludemann ludemann@mlpvm1.iinus1.ibm.com
(the above are my opinions and almost certainly not
those of my employer nor of my co-workers)
Technical Details
Message-ID:
<35150@cup.portal.com>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!fernwood!portal!cup.portal.com!pglReferences:
<9888@bunny.GTE.COM> <3992@goanna.cs.rmit.oz.au> <1920@tuvie> <35019@cup.portal.com> <4037@goanna.cs.rmit.oz.au>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!fernwood!portal!cup.portal.com!pgl From: pgl@cup.portal.com (Peter G Ludemann) Newsgroups: comp.lang.prolog Subject: Re: Standards question: behavior of arg/3 Message-ID: <35150@cup.portal.com> Date: 22 Oct 90 18:36:42 GMT References: <9888@bunny.GTE.COM> <3992@goanna.cs.rmit.oz.au> <1920@tuvie> <35019@cup.portal.com> <4037@goanna.cs.rmit.oz.au> Organization: The Portal System (TM) Lines: 59