Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!news.duke.edu!convex!cs.utexas.edu!swrinde!ihnp4.ucsd.edu!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!lee
From: lee@munta.cs.mu.OZ.AU (Lee Naish)
Subject: Re: numbervars/3 bug in Quintus and Sicstus
Message-ID: <9430016.21535@mulga.cs.mu.OZ.AU>
Sender: news@cs.mu.OZ.AU
Organization: Department of Computer Sci, University of Melbourne
References: <38jqt7$5bn@coli-gate.coli.uni-sb.de> <PEREIRA.94Oct25231821@alta.research.att.com> <38lgc9$m8k@coli-gate.coli.uni-sb.de>
Date: Thu, 27 Oct 1994 06:00:38 GMT
Lines: 84

In article <38lgc9$m8k@coli-gate.coli.uni-sb.de> erbach@coli.uni-sb.de (Gregor Erbach) writes:
>pereira@alta.research.att.com (Fernando Pereira) writes:
>
>>In article <38jqt7$5bn@coli-gate.coli.uni-sb.de> erbach@coli.uni-sb.de (Gregor Erbach) writes:
>>> The Sicstus manual states that numbervars(Term,FirstVar,LastVar)
>>>
>>>    Unifies each of the variables in term @var{Term} with a special term ...
>>>
>>> Consider what happens when I call
>>>
>>>    ?- numbervars('$VAR'(X),0,N).
>>>
>>> The solution I get is X = 0, N = 1; instead 
>>> of the expected X = '$VAR'(0), N = 1. 

There are two main reasons for using numbervars.

The first is as a hack to get variables printed in a nicer way.

>     ?- numbervars(['$VAR'(X),X],0,N).

This goal followed by write(['$VAR'(X),X]) will produce an unexpected
result with Sicstus.

The second is as a way to get a ground meta level representation of
possibly non-ground Prolog term.  If the term to be represented contains
'$VAR'/1 numbervars cannot work, a severe limitation. The mapping
numbervars implements is many to one so the result is ambiguous.  For
example, numbervars('$VAR'(0), 0, N) and numbervars(X, 0, N) produce the
same term.  The Sicstus implementation is no better or worse in this
regard.

>>It is not a bug, it was designed to behave as you describe back in
>>DEC-10 Prolog. There's absolutely no reason for your program to use
>>terms with functor '$VAR'/1 except when matching against the results
>>of numbervars/3, which may contain ground terms with that principal
>>functor.

As soon as you have code using '$VAR'/1, it may be used as input *data*
to (meta) programs.  If you use numbervars you are then stuffed.  And
with the Sicstus version I suspect listing may be broken (it often uses
numbervars).


BTW, this topic comes up regularly.

	lee

>
>There is some confusion here. My program does not use terms with functor
>'$VAR'/1, but a user of my system uses the '$VAR'/1 terms exactly with
>the purpose of matching against the results of numbervars/3. However,
>when his program is compiled into a Prolog program, a term '$VAR'(_) is
>just replaced by a variable.
>
>Also, note that the implemented behaviour can also have the effect of
>replacing a variable by a number, which can certainly not be the intended
>behaviour of numbervars/3.
>
>     ?- numbervars(['$VAR'(X),X],0,N).
>
>     N = 1, X = 0  
>
>>Unfortunately, almost everyone else wants the implemented behavior,
>
>I have a hard time thinking of a situation where it would be preferable 
>to have '$VAR'(X) printed out as a variable (e.g. A), instead of '$VAR'(A),
>and getting other occurrences of X instantiated by a number.
>
>I would prefer the behaviour as described in the manuals. 
>
>Gregor Erbach
>
>
>---------------------------------------------------------------------------
>* Gregor Erbach - Universitaet des Saarlandes - Computational Linguistics *
>*        Im Stadtwald - POB 151150 - D-66041 Saarbruecken - Germany       *
>*   erbach@coli.uni-sb.de * Tel +49/681 302-4117 * Fax +49/681 302-4700   *
>*                  URL: http://coli.uni-sb.de/~erbach                     *
>---------------------------------------------------------------------------
>
>


