Subject: Re: [SWIPL] biginer's question.

From: "Richard A. O'Keefe" <[email-masked]>
Date: Tue, 27 Mar 2001 14:26:13 +1200 (NZST)

Prasad Manjre <[email-masked]> is still struggling:
    As you have quoted in your example, I created another list & stored the
    rest of list into that i.e
    X1= ([1,3,4])
    But while using this list in the another loop,as soon as the control
    moves to that list the compiler treats X1 as new variable & the values
    stored in it in the previous loop gets lost.& the compiler treats this X1
    as the empty list.
    So will you guide me to use the contets stored in the list X1 to use it
    for the another loop?

I find it very difficult to understand this.
If a ".ac.in" site is some kind of tertiary educational institution
(as a ".ac.nz" site is), surely there is some kind of library with at
least one good Prolog textbook in it?

To understand any programming language, you have to understand its
rules about variable names.  Most programming languages say that a
name stands for a particular thing only within a certain chunk of
text (typically a procedure) where it is declared.  Prolog is just
the same.  A Prolog variable name is visible only within a SINGLE
clause.  Thus in

    p(X) :- q(X, Y), r(Y).
    p(X) :- w(Y), v(Y, X).

there are *TWO* variables called X (one in the first clause and one
in the seocnd) and *TWO* variables called Y (one in the first clause
and one in the second).  There are only two ways you can transmit
information from one clause to another:
 - put it in the mutable data base (slow, easy to get wrong)
 - pass it as a parameter (fast, preferred).

Prolog variables are not like C or Pascal variables where you can store
a value into a variable at any time, even when it HAS a value.  In Prolog,
you can only bind a variable to a value when it doesn't have a value yet.

I think the best thing would be to

 - tell us what problem you are trying to solve (not what difficulty with
   Prolog you are trying to overcome), and
 - show us your actual code.

But reading a good Prolog book would be better still, because it would be
far more helpful to you.