Article View: net.lang.prolog
Article #608Re: Standard behavior?
From: James H. Cox
Date: Tue, 13 May 1986 13:52
Date: Tue, 13 May 1986 13:52
55 lines
2252 bytes
2252 bytes
In article <6500005@uicsl> gooley@uicsl.UUCP writes:
>
>Consider the following trivial predicate:
>
>a([]).
>a(_).
>
>Given the query :-a([]). , C-Prolog finds one match and UNSW Prolog finds two.
>Which is standard behavior? How do other implementations behave?
>
Hmmmm, not exactly.
Depends on what you mean by finding a match and how you apply
the query. If you type
a([]).
to the C-prolog interpreter it comes back and says 'yes', ie the
predicate can be satisfied. However, when you present such a query to
the C-prolog top level interpreter it doesnt give you any opporunity
to backtrack, you only get this opportunity if there are any variables
given in your query, and you make use of this opportunity by typing
';' which invites the interpreter to backtrack.
Below follows two dialogs with C prolog that indicate there are indeed
two solutions to the query you mentioned.(Note that '?-' is the
interpreter's prompt for you to type a query, and that ^ appears under
user input)
?- a(X). -- initial query
^^^^^
X = [] ; -- first solution, ; typed so invoke
^ backtracking.
X = _0 ; -- second solution..
^
no -- prolog says no more solutions.
?- a([]), write(a), fail. -- need to phrase it like this to
^^^^^^^^^^^^^^^^^^^^^^ invoke backtracking since the
interpreter will not give us the
opportunity..
aa -- indicates 'write(a)' called twice.
no -- no more solutions.
?-
--
UUCP : { ENGLAND or WALES }!ukc!aber-cs!jhc
JANET: jhc@uk.ac.aber.cs PHONE: +44 970 3111 x 3373
Post: University College of Wales, Penglais, Aberystwyth, UK, SY23 3BZ.
Technical Details
Message-ID:
<234@aber-cs.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!linus!philabs!cmcl2!seismo!mcvax!ukc!dcl-cs!aber-cs!jhcReferences:
<6500005@uicsl>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!linus!philabs!cmcl2!seismo!mcvax!ukc!dcl-cs!aber-cs!jhc From: jhc@aber-cs.UUCP (James H. Cox) Newsgroups: net.lang.prolog Subject: Re: Standard behavior? Message-ID: <234@aber-cs.UUCP> Date: Tue, 13-May-86 09:52:01 EDT Article-I.D.: aber-cs.234 Posted: Tue May 13 09:52:01 1986 Date-Received: Fri, 16-May-86 06:33:36 EDT References: <6500005@uicsl> Reply-To: jhc@uk.ac.aber.cs (James H. Cox) Organization: University College of Wales, Aberystwyth, UK. Lines: 55 Keywords: prolog