[eclipse-users] Matching

From: Lutz, Charles D <charles.d.lutz_at_...53...>
Date: Tue, 08 May 2007 11:47:55 -0400
Hi folks,


As a new user both of Prolog and of ECLiPSe, I'll probably have a lot of

I'm slllooooowwwwwllly working through the tutorial book. I'm finding I
need more

explanations for quite a lot of the examples.


Currently I'm looking at section 4.6, "Matching".  To play with the
example, I made

both a "normal" version and a "matching" version:


  %From section 4.6:


  %version without matching:


  p1(f(a, X)) :- writeln(X).


  %version with matching:


  p2(f(a, X)) ?- writeln(X).


Here are some runs:


  [eclipse 17]: p2(F).


  No (0.00s cpu)

  [eclipse 18]: p2(f(A, B)).


  No (0.00s cpu)

  [eclipse 19]: p2(f(A, b)).


  No (0.00s cpu)

  [eclipse 20]: p2(f(a, b)).



  Yes (0.00s cpu)

  [eclipse 21]: p1(F).



  F = f(a, X)

  Yes (0.00s cpu)

  [eclipse 22]: p1(f(A, B)).



  A = a

  B = B

  Yes (0.00s cpu)

  [eclipse 23]: p1(f(A, b)).



  A = a

  Yes (0.00s cpu)

  [eclipse 24]: p1(f(a, b)).



  Yes (0.00s cpu)


To be honest, the outputs of both of these variants are not totally
clear to me. First off,

what does it "mean" to have "f(a, X)" inside of the head clause? Apart
from saying p1

or p2 is a clause of arity 1, whose argument is another clause of arity
2, what is the

"practical" meaning of it?  This might help me to understand the first
output of p1 and the

difference between the second and third outputs of p1. In all success
cases, I'm taking it

that the first line of output is the result of the writeln/1.


Thanks in advance for any tips,


Chuck Lutz

Lockheed Martin

Systems of Systems Engineering

BMC4I Modeling and Simulation

Moorestown, NJ

(856)638-7234 (office)



"A graphic is never an end in itself; it is a moment

in the process of decision making."
     - Jacques Bertin

Received on Tue May 08 2007 - 16:48:19 CEST

This archive was generated by hypermail 2.3.0 : Sun Aug 25 2019 - 06:15:49 CEST