From: Dan Kennedy
Subject: Pass array by value in AKCL - I'm confused (and new to lisp)
Date: 
Message-ID: <C8HIA7.Gz2@undergrad.math.uwaterloo.ca>
Hi!

I'm just new to LISP, and I'm using AKCL.

I understood that everything in LISP was passed by value, but it's not
this way for arrays. SO, how do I passed an array by value? I saw in a
book something about "value-of" but my implentation doesn't seem to have 
that?

I get this:

>(setq a (make-array `(3 3) :initial-element `A))
#2A((A A A) (A A A) (A A A))

>(setq b a)
#2A((A A A) (A A A) (A A A))

>(setf (aref a 0 0) `Q)
Q

>a
#2A((Q A A) (A A A) (A A A))

>b
#2A((Q A A) (A A A) (A A A))


Does this have to do with setf or setq?  

Note: This example isn't exactly what I'm doing, but it does show the
problem I'm having.  I'm actually passing the array as a parameter to a
function.  I want that function to change a copy of the array to put 
somewhere else.  As I have to do this a few times with different criteria,
I want to pass a copy of the array, change it, pass the original version
again, change it, etc.


Am I missing something? 

Thanks!

Dan
-- 
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
"...This next song answers the rhetorical question, "Is this 
any good?"...The answer being, of course, "That's any good."
		- Moxy Fruvous 

From: Barry Margolin
Subject: Re: Pass array by value in AKCL - I'm confused (and new to lisp)
Date: 
Message-ID: <1vdgkgINNlil@early-bird.think.com>
In article <··········@undergrad.math.uwaterloo.ca> ········@undergrad.math.uwaterloo.ca (Dan Kennedy) writes:
>I understood that everything in LISP was passed by value, but it's not
>this way for arrays. SO, how do I passed an array by value? I saw in a
>book something about "value-of" but my implentation doesn't seem to have 
>that?

In Lisp, the value of a variable is an object, and that object itself,
rather than a reference to the variable, is passed to a function.  The
difference between this and passing by reference is only apparent when you
assign to a parameter variable:

> (defun foo (array)
    (setf (aref array 0) 1)
    (setq array 'b))
FOO
> (setq a (vector 0 1 2))
#(0 1 2)
> (foo a)
B
> a
#(1 1 2)

If Lisp used call by reference, the value of A would be B.

>Note: This example isn't exactly what I'm doing, but it does show the
>problem I'm having.  I'm actually passing the array as a parameter to a
>function.  I want that function to change a copy of the array to put 
>somewhere else.  As I have to do this a few times with different criteria,
>I want to pass a copy of the array, change it, pass the original version
>again, change it, etc.

The function will have to make a copy of the array using explicit code.
There's no standard built-in function to make a copy of an array.
-- 
Barry Margolin
System Manager, Thinking Machines Corp.

······@think.com          {uunet,harvard}!think!barmar
From: Lawrence G. Mayka
Subject: Re: Pass array by value in AKCL - I'm confused (and new to lisp)
Date: 
Message-ID: <LGM.93Jun13123027@excalibur.flw.att.com>
In article <············@early-bird.think.com> ······@think.com (Barry Margolin) writes:

   In article <··········@undergrad.math.uwaterloo.ca> ········@undergrad.math.uwaterloo.ca (Dan Kennedy) writes:

   >Note: This example isn't exactly what I'm doing, but it does show the
   >problem I'm having.  I'm actually passing the array as a parameter to a
   >function.  I want that function to change a copy of the array to put 
   >somewhere else.  As I have to do this a few times with different criteria,
   >I want to pass a copy of the array, change it, pass the original version
   >again, change it, etc.

   The function will have to make a copy of the array using explicit code.
   There's no standard built-in function to make a copy of an array.

There is, at least, COPY-SEQ, which will make a copy of a
1-dimensional array (among other things).  But it is true that Common
Lisp lacks functions (or, better, a single function) to copy objects
such as:

- Hash tables

- General arrays

- General list structure (preserving circularities and
structure-sharing)

- CLOS instances

Ironically, Common Lisp implementations must do just such copying--in
a very inefficient way, by flattening and reconstruction--to maintain
compilation/loading semantics.  (See the discussion in CLtL2 of
"Similarity of Constants", MAKE-LOAD-FORM, and
MAKE-LOAD-FORM-SAVING-SLOTS.)  But this useful capability is not
typically made directly available--using the obvious and efficient
means, without the intermediation of a flat file--to programmers; so
everyone writes their own instead.


        Lawrence G. Mayka
        AT&T Bell Laboratories
        ···@iexist.att.com

Standard disclaimer.
--
        Lawrence G. Mayka
        AT&T Bell Laboratories
        ···@iexist.att.com

Standard disclaimer.