From lalit@savvion.com  Wed Sep  6 21:25:34 2000
Received: from oahu.savvion.com (oahu.savvion.com [206.40.33.137])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id VAA17887
	for <prolog@swi.psy.uva.nl>; Wed, 6 Sep 2000 21:25:33 +0200 (MET DST)
Received: from neptune.tdiinc.com (lalit@neptune.savvion.com [10.1.4.46])
	by oahu.savvion.com (8.9.3/8.9.3) with ESMTP id MAA10582;
	Wed, 6 Sep 2000 12:23:43 -0700 (PDT)
Received: from localhost (lalit@localhost)
	by neptune.tdiinc.com (8.9.0/8.9.0) with ESMTP id MAA06505;
	Wed, 6 Sep 2000 12:22:28 -0700 (PDT)
X-Authentication-Warning: neptune.tdiinc.com: lalit owned process doing -bs
Date: Wed, 6 Sep 2000 12:22:28 -0700 (PDT)
From: Lalit Jain <lalit@savvion.com>
To: "Justice, Randy -CONT" <Randy.Justice@cnet.navy.mil>
cc: "Prolog@Swi. Psy. Uva. Nl (E-mail)" <prolog@swi.psy.uva.nl>
Subject: Re: Removing the first element
In-Reply-To: <B4CA1F5D8D23D411ADC7009027E791BF1DF4E4@pens0394.cnet.navy.Mil>
Message-ID: <Pine.GSO.4.21.0009061210350.23697-100000@neptune.tdiinc.com>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII


I think the fundamental concept you're missing is the difference between
variable assignment and instantiation. Unlike in other languages where you
can assign/reassign a value to a variable, in Prolog, variable get
instantiated ( as opposed to being assigned ). And once a
variable is instantiated you cannot modify/reassign it. (In case of
backtracking though, these instantiations are undone and redone to produce
alternative results).
Hence in your ex. if X=[a,b],
then [Y|X] = X cannot reassign X to [b], becuase X is already [a,b],
hence, the system ends up checking if [Y|[a,b]] = [a,b] which fails.

Hope this helps.
Regards,
Lalit
---							
Lalit Kumar Jain	SavVion Inc.
@ 408-330-3431		http://www.savVion.com
---			


On Wed, 6 Sep 2000, Justice, Randy -CONT wrote:

> I was trying to remove the first element of the list and return the results
> in the parameter.
> I have two rules: test  and test1.   Why don't test1 work?   What is the
> fundamental rule that I am missing??  How does one assign a value to a
> parameter --(with numbers one can use "is") ?
> 
> test(X):-
>    write(X),
>    write('\n'),
>    [Y|Z] = X,
>    write(Y),
>    write('\n'),
>    write(Z).
> 
> test1(X):-
>    write(X),
>    write('\n'),
>    [Y|X] = X,
>    write(Y),
>    write('\n'),
>    write(X).
> 
> ?- test([[1,2],[1,2,3,4]]).
> [[1, 2], [1, 2, 3, 4]]
> [1, 2]
> [[1, 2, 3, 4]]
> 
> Yes
> ?- test1([[1,2],[1,2,3,4]]).
> [[1, 2], [1, 2, 3, 4]]
> 
> No
> 
> 
> Thanks again... 
> 
> Randy
> 
> 
> ----------------
> * To UNSUBSCRIBE, please use the HTML form at
> 
>     http://www.swi.psy.uva.nl/projects/SWI-Prolog/index.html#mailinglist
> 
> or send mail to prolog-request@swi.psy.uva.nl using the Subject: "unsubscribe"
> (without the quotes) and *no* message body.
> 
> ** An ARCHIVE of this list is maintained at
> 
>     http://www.swi.psy.uva.nl/projects/SWI-Prolog/mailinglist/archive/
> 
> 

