Subject: Re: Anonymous variables

From: Jan Wielemaker <[email-masked]>
Date: Fri, 9 Jul 1999 16:44:04 +0200

On Fri, 09 Jul 1999, Luis Iraola Moreno wrote:

>Just a remark about how SWI (3.2.7) handles anonymous variables.
>
>During compile time, any expression starting with an underscore (e.g.
>"_var") is considered an anonymous variable: the compiler stops warning
>you about using the variable just once in a clause. 
>
>But in run time, only expressions consisting *only* of an underscore
>are treated as anonymous variables. E.g.
>
>?- _ = a, _ = b.
>yes.
>
>Perfect, the unification of the anonymous variable "_" in the first goal
>is not taken into account when proving the second. But
>
>?- _var = a, _var = b.
>no.

Just '_' is an anonymous variable.  _name is a normal variable, though
singleton checking does not warn you.

I don't know by heart wat ISO says.  The motivation is for compatibility
with BIM-Prolog, which used _var for normal variables (and some projects
had to be portable long ago).  In practice,  Use ThisVar for normal
variables, _ if you really want announynous and _var to add comment to
it.   Maybe there should be a feature declaraction to control this
behaviour.

>Here the first unification of "_var" is maintained when trying to prove
>the second goal, therefore it fails.
>
>So, I guess that expressions like "_var" are just like any other standard
>variable (though the compiler does not warn you) and only "_" names the
>anonymous variable.
>
>This posses no problem at all (I am not claiming it is a bug), but
>sometimes it is convenient (I think) to have "named" anonymous variables
>like "_Digit" just for improving the readability of the code.

	--- Jan