Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between _ and _variable in prolog?

Tags:

syntax

prolog

I have encountered a lot of problems with a literal that starts with a _ such as _Peter. So what exactly would be the difference between:

good(_,_).

and

good(_,_Peter).

Thank you for answering my question!

like image 629
SDG Avatar asked Jun 12 '15 17:06

SDG


People also ask

What does underscore mean in Prolog?

A single underscore ( _ ) denotes an anonymous variable and means "any term". Unlike other variables, the underscore does not represent the same value everywhere it occurs within a predicate definition. A compound term is composed of an atom called a "functor" and a number of "arguments", which are again terms.

What is the difference between and == in Prolog?

The = "operator" in Prolog is actually a predicate (with infix notation) =/2 that succeeds when the two terms are unified. Thus X = 2 or 2 = X amount to the same thing, a goal to unify X with 2. The == "operator" differs in that it succeeds only if the two terms are already identical without further unification.

Which of the following are variables in Prolog?

Variables. A variable is a string of upper-case letters, lower-case letters, digits and underscore characters that starts either with an upper-case letter or with an underscore. For example, X , Y , Variable , _tag , X_526 , List , List24 , _head , Tail , _input and Output are all Prolog variables.


1 Answers

_ alone is an anonymous variable. Multiple occurrences in the same clause (or the same read-term) represent different variables.

A variable starting with _ but containing further characters is not an anonymous variable. Several occurrences represent the same variable.

By convention, many Prolog systems require that variables occurring only once need to start with a _. But this is a convention leading in most implementations to warnings only.

like image 160
false Avatar answered Sep 18 '22 03:09

false