Article View: comp.lang.prolog
Article #1282Re: Standards question: behavior of arg/3
From: Peter G Ludemann
Date: Fri, 19 Oct 1990 03:31
Date: Fri, 19 Oct 1990 03:31
67 lines
2736 bytes
2736 bytes
| In article <3992@goanna.cs.rmit.oz.au> ok@goanna.cs.rmit.oz.au
| (Richard A. O'Keefe) writes:
| [...discussion of design principles for BIPs...]
| > ?- 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?
I implemented such an arg/3 at university -- it never even
occured to me to check how Edinburgh does it because it seemed
the natural way to do things. And IBM-Prolog also provides
such a facility (not implemented nor designed by me, by the
way) but it also provides the conventional Edinburgh flavour
for those who demand compatibility. [Richard O'Keefe notes
that his proposal is not compatible with Edinburgh Prolog,
by the way -- "a foolish consistency is the hobgoblin of small
minds" (Emerson, I think).]
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)
IBM also a delayed version of arg/3 which will wait until
the functor is instantiated. It allows things like:
:- wait:arg(N, F, X) , F = f(a) , N = 1.
to succeed with N=1, F=f(a), X=a.
Here's an annotated console trace:
% --- switch to Edinburgh syntax and predicates:
<- switch(synt2).
goal : <- switch(synt2) .
48ms success
<- switch(synt2) .
% --- demonstrate compatibility with Edinburgh predicate arg/3:
:- arg(0, [a,b,c], N) .
goal : <- arg(0,[a,b,c],V1) .
0ms fail
<- arg(N, [a,b,c], X) . % no error message!
goal : <- arg(V1,[a,b,c],V2) .
0ms fail
:- arg(1, [a,b,c], X) . % succeeds with X = a
goal : :- arg(1,[a,b,c],V1) .
0ms success
:- arg(1,[a,b,c],a) .
% --- now show what happens with the non-Edinburgh flavour
% --- of arg/3. We must use the "built" prefix to get it
% --- because the Edinburgh flavour (built2:arg/3) is default
% --- when we're in Edinburgh syntax. Alternatively, we could
% --- have declared "built" to be the default prefix for arg/3.
:- built:arg(N, [a,b,c], X) , built:write(N:X) , fail .
goal : :- built : arg(V1,[a,b,c],V2) , built : write(V1 : V2) , fail .
0 : '.' .
1 : a .
2 : [b,c] .
0ms fail
- Peter Ludemann ludemann@mlpvm1.iinus1.ibm.com
Technical Details
Message-ID:
<35019@cup.portal.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!apple!portal!cup.portal.com!pglReferences:
<9888@bunny.GTE.COM> <3992@goanna.cs.rmit.oz.au> <1920@tuvie>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!apple!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: <35019@cup.portal.com> Date: 19 Oct 90 03:31:20 GMT References: <9888@bunny.GTE.COM> <3992@goanna.cs.rmit.oz.au> <1920@tuvie> Organization: The Portal System (TM) Lines: 67