[Openmcl-devel] Strange LISP Clozure problems
Doug Currie
dcurrie at parasimtech.com
Fri Oct 1 07:38:18 PDT 2010
Hi Lonnie,
The function copy-list is a shallow copy (as is remove-if-not).
From http://www.lispworks.com/documentation/HyperSpec/Body/f_cp_lis.htm
> Only the list structure of list is copied; the elements of the resulting list are the same as the corresponding elements of the given list.
http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_l.htm#list_structure
You should take a look at copy-tree
http://www.lispworks.com/documentation/HyperSpec/Body/f_cp_tre.htm
e
On Oct 1, 2010, at 9:57 AM, Lonnie Cumberland wrote:
> Greetings All,
>
> I am working on some code in lisp and basically have 2 lists now after
> originally trying with just one where I had the same problem. (I also
> had a plist version but still get the same problem.)
>
> I make a list for a format of
>
>
> ((1 nil nil 1)
> .
> .
> .
> (n nil nil 1))
>
> call it *db*. I then add some values such that the first "nil" is made
> into a list. [ie.. (1 (2) nil 1) ] and then do this for the whole list
> in *db* with the function below.
>
> (defun add-mod-pres (b)
> (mapcar
> #'(lambda (row) (setf (second row) (nconc (second row) (list
> (mod (first row) b))))) *db*)
> )
>
> The problem comes when I try to make a copy of the *db* and then
> change some value in the "copied" db.
>
> (setf tempdb (copy-list (remove-if-not #'(lambda (row) (equal (first
> (last row)) (list j))) *db*)))
>
> The result I am getting is that things as also being changed in the
> original *db* as well and it look as though there is something going
> on with LISP using pointers instead of actually making a copy.
>
> The basic code problem is to have my list like:
>
> ((1 nil nil 1)
> .
> .
> .
> (n nil nil 1))
>
> and while iterating over some other lists that I have, I grow each
> list like the below example of a single sublist within *db*:
>
> Iteration 1
> (1 (2) (1) 1)
>
> Iteration 2
> (1 (2 1) (1 5) 1)
>
> .
> .
>
> Iteration 10
> (1 (2 1 3 4 5 4 3 2 1 0) (1 5 3 2 4 5 4 4 5 3) 1)
>
> etc....
>
> What I am currently getting is that when I modify the (1 5 .... ) list
> then it also seems to modify the (2 1 .....) list in the *db* and this
> also happens if I modify the (1 5 ....) list in the tempdb which also
> modifies the *db* list.
>
> There seems to be some shared memory in the lists going on and I don't
> know how to stop it.
>
> Could the "lambda" or "mapcar" functions be the problem?
>
> Kind Regards and have a great day,
> Lonnie T. Cumberland
>
> "BTE, bringing people together today to meet the world's energy needs
> of tomorrow......"
>
> < CONFIDENTIALITY NOTICE >
>
> The information contained in this transmission is intended only for
> the person or entity to which it is addressed and may contain
> confidential and/or privileged material. If you are not the intended
> recipient of this information, do not review, retransmit, disclose,
> disseminate, use, or take any action in reliance upon, this
> information. If you received this transmission in error, please
> contact the sender and destroy all printed copies and delete the
> material from all computers.
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
--
Doug Currie, CTO
Parallel Simulation Technology LLC
5 Dartmouth Drive
Auburn, NH 03032 USA
Tel. 603-644-4500 main
Tel. 603-622-3749 x41 direct
More information about the Openmcl-devel
mailing list