From: Salvador Gonzalez Gonzalez
Subject: Pointer to a list
Date: 
Message-ID: <334E292F.1BA7@arrakis.es>
    I'm a begginer in LISP..... I need something that I think is very
simple:

        I need to change the value of a defun argument, I mean:

    (defun try (List1)
        (setf List1 '(1 2 3))
    )

And if I have:

(setf List1 '(a b c))
(try list1)
list1
(1 2 3)

Can someone help me ????

Thanks...
From: Thomas A. Russ
Subject: Re: Pointer to a list
Date: 
Message-ID: <ymid8s1fvhz.fsf@hobbes.isi.edu>
In article <...> Salvador Gonzalez Gonzalez <······@arrakis.es> writes:
 > 
 >     I'm a begginer in LISP..... I need something that I think is very
 > simple:
 > 
 >         I need to change the value of a defun argument, I mean:

Actually, you probably don't need to do this.  Although it is
technically possible for non-NIL input lists, it would be a rather
strange application that actually required this capability.

As a beginner, it would be better to adopt a more Lisp-like style, since
that will make your future work with lisp simpler.  The fundamental
principle is that list structures are not mutated.  New versions are
created instead.  What this means is that you will not have functions
that modify their input parameters at all.  If different values are to
be used, then they are set in the calling function, not in the called
function.

 >     (defun try (List1)
 >         (setf List1 '(1 2 3))
 >     )
 > 
 > And if I have:
 > 
 > (setf List1 '(a b c))
 > (try list1)
 > list1
 > (1 2 3)
 > 
 > Can someone help me ????

The lisp way would be to have:

 (defun try (list1)
   ...
   '(1 2 3))

 (setf List1 '(a b c))
 (setf List1 (try list1))
 list1
 (1 2 3)

There really isn't any reason to modify the variable that points to the
input parameter.  This is all handled by assignment operations in the
calling function.  That is because setting the value to a new list
generally means you want the pointer to a different object.

[Changing the state of objects is another matter, but then it is also
 easy to accomplish.]

So there isn't any need for modifying variables that are used to pass
values to function calls.  If you want to have changes to more then one
input, there are multiple-value return forms that allow multiple values
to be returned and bound:

(defun try2 (in1 in2)
  (values (reverse in1) (reverse in2)))

(setf in1 '(1 2 3))
(setf in2 '(a b c))
(multiple-value-setq (in1 in2) (try2 in1 in2))

in1 => '(3 2 1)
in2 => '(c b a)

-- 
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu