M
Matthias Luedtke
Christian Neukirchen wrote:
[SWI-Prolog]
You're right, the semantics of both constructs differs:
foo(bar,baz,42).
foo(bar,bar,42).
foo(baz,baz,42).
% E:/Dokumente/Studium/Passau/5.
Semester/DeduktiveDB/PrologWorkspace/RubyNEwsgroup.pl compiled 0.00 sec,
944 bytes
Yes
3 ?- foo(A,A,C).
A = bar
C = 42 ;
A = baz
C = 42 ;
No
As you see in the above query Prolog unifies the query variable A with
the same atom whereas the query
4 ?- foo(_,_,C).
yields
C = 42 ;
C = 42 ;
C = 42 ;
No
and therefore in this respect is equivalent to this query:
5 ?- foo(A,B,C).
A = bar
B = baz
C = 42 ;
A = bar
B = bar
C = 42 ;
A = baz
B = baz
C = 42 ;
No
However in the underscore version you don't get to see which atoms the
variables got unified with.
In this example there is in effect no real query /condition/ when you
write A,B,C or _,_,C. On the other hand the query :- foo(A,A,C) states
that the first two parameters must hold the same value.
Although :- foo(A,B,C) and :- foo(_,_,C) have same query semantics the
underscore version is a lot easier on the eye in my opinion. Writing
4711.times{ |_| puts "Ruby rocks" } seems odd to me, though.
Regards,
Matthias
[SWI-Prolog]
I'm not sure they are "old variables"... compare foo(A, A, B) and
foo(_, _, B). I don't think they share the same semantics.
You're right, the semantics of both constructs differs:
foo(bar,baz,42).
foo(bar,bar,42).
foo(baz,baz,42).
% E:/Dokumente/Studium/Passau/5.
Semester/DeduktiveDB/PrologWorkspace/RubyNEwsgroup.pl compiled 0.00 sec,
944 bytes
Yes
3 ?- foo(A,A,C).
A = bar
C = 42 ;
A = baz
C = 42 ;
No
As you see in the above query Prolog unifies the query variable A with
the same atom whereas the query
4 ?- foo(_,_,C).
yields
C = 42 ;
C = 42 ;
C = 42 ;
No
and therefore in this respect is equivalent to this query:
5 ?- foo(A,B,C).
A = bar
B = baz
C = 42 ;
A = bar
B = bar
C = 42 ;
A = baz
B = baz
C = 42 ;
No
However in the underscore version you don't get to see which atoms the
variables got unified with.
In this example there is in effect no real query /condition/ when you
write A,B,C or _,_,C. On the other hand the query :- foo(A,A,C) states
that the first two parameters must hold the same value.
Although :- foo(A,B,C) and :- foo(_,_,C) have same query semantics the
underscore version is a lot easier on the eye in my opinion. Writing
4711.times{ |_| puts "Ruby rocks" } seems odd to me, though.
Regards,
Matthias