Use with Prolog anonymous variables (_), a single underscore by itself. Do not use with a normal variable starting with an underscore, e.g. _name. Do not use this with an anonymous type found in other programming languages such as C#, Scala, Go.
Questions tagged [prolog-anonymous-variable]
10 questions
13
votes
1 answer
Prolog anonymous variable
Here is what I have understood about Prolog variables.
A single underscore stands for anonymous variable, which is like a new variable each time it occurs.
A variable name starting with underscore like _W is not an anonymous variable. Or, the…

Gurkan E.
- 205
- 1
- 2
- 7
4
votes
1 answer
Prolog: Redundant results in clauses involving anonymous variables
Consider the following Prolog program.
a(X) :- b(_), c(X).
b(1).
b(2).
b(3).
c(1).
Running the query:
a(X).
in SWI-Prolog, we get three results, all X = 1.
Given that we do not care about the anonymous variable, what is preventing SWI-Prolog to…

Alberto Illobre
- 45
- 1
- 4
3
votes
1 answer
First order logic Prolog anonymous variables
The Prolog rule below:
grandparent(X,Z) :- parent(X,Y) , parent(Y,Z)
In first order logic is going to be:
∀x ∀y ∀z ((P (x, y) ∧ P (y, z)) → G(x, z))
In theory if we have an anonymous variable in our Prolog rule something like:
grandparent(X,Z) :-…

I scan
- 65
- 5
2
votes
2 answers
How are anonymous variables interpreted in Prolog?
A quick and simple question regarding what role anonymous variables play in the resolution of a Prolog query given a set of program rule. So, the way I understand how the simplest form of SLD resolution works, an SLD tree is constructed by taking…

sanik98
- 145
- 6
2
votes
1 answer
How does the predicate 'append/3' work with an anonymous variable in Prolog?
How exactly does append/3 work with an anonymous variable such as the one in the example below:
append(_,[b(F,ND,P)|Rest],Visited).
Couldn't we in fact just use append/2?
Thank you for your answer!

SDG
- 2,260
- 8
- 35
- 77
2
votes
4 answers
Prolog and List Unification
I'm trying to further my understanding of Prolog, and how it handles unification. In this case, how it handles unification with lists.
This is my knowledgebase;
member(X, [X|_]).
member(X, [_|T]):- member(X, T).
If I'm understanding the process…

Martyn Shutt
- 1,671
- 18
- 25
1
vote
3 answers
Prolog: Matching One or More Anonymous Variables
[_, [ X , _ ],_] will match a list like [d, [X,a], s]. Is there a way to match it to any pattern where there is one or more anonymous variables? ie. [[X,a],s] and [[d,a],[p,z], [X,b]] would match?
I am trying to write a program to count the elements…

Rory Flast
- 83
- 6
1
vote
1 answer
Comparing prolog anonymous variables
I have a series of facts in prolog that contain the anonymous variable _.
fact(a, _).
fact(b, _).
fact(c, _).
and i have some rules that take in lists of these facts:
f([H | T]) :- H == fact(a, _),
% stuff %
.
however…

calccrypto
- 8,583
- 21
- 68
- 99
0
votes
1 answer
Different answers when using anonymous variable and "normal" variable in Prolog
I have the following database:
vegetarian(jose).
vegetarian(james).
vegetable(carrot).
vegetable(egg_plant).
likes(jose,X):-vegetable(X).
loves(Who,egg_plant):-vegetarian(Who).
When I do the query vegetarian(_). I was expecting to get _ = jose; _ =…

rhododendron
- 5
- 3
0
votes
1 answer
anonymous variables - prolog - a few queries
Can you help me understand the engine of answering the next queries?
?- _ = _.
?- _ = 1.
?- A = _, B = _, C = A + B + 1.
And some extra query (not related to anonymous variables):
?- B = A + 1, A = C, C = B - 1.
I know the answers to above…

Roni Koren Kurtberg
- 495
- 1
- 8
- 18