[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: COPY ?



    Date: 19 December 1980 23:05-EST
    From: Carl W. Hoffman <CWH at MIT-MC>
    .  .  .
    My objection to COPY is that its ambiguous.  People have used that name in
    the past for several different meanings.  For that reason, I introduced the
    names COPY-CONS, COPY-TOP-LEVEL, and COPY-ALL-LEVELS into Macsyma.  These
    operations just aren't preformed frequently enough to warrant shorter 
    names.  Of course, we'll go along with what the Lispm/NIL people choose ...
Even in system code, I'm quite certain that all three version of "copy"ing are 
needed; for example, the DEFMAX macro cache needs to call COPY-CONS (which
I presume should be an error if applied to some structured thing other
than a pair, such as an s-expression array or a vector). 
   On the otherhand, I suggest something slightly more general than COPY-CONS
so that one could get a new copy of an array/vector without having any of
its elements copied; say, COPY1.  At the very least, I'd suggest the name 
COPY-PAIR, with COPY-CONS a synonym thereof, but I believe COPY1 would be
adequate.
   If COPY-TOP-LEVEL could be called COPY-SEQUENCE, then its definition
would be quite straightforward -- just COPY1'ing all the successive tails
of a list, and just COPY1 itself on an array/vector.   I should like to
see the name COPY-TOP-LEVEL be defined as doing a COPY1 on each element
of a sequence.  Then COPY* could be a two-arg function whose optional second
arg is a "count" of maximum depth to descend while copying -- some large
integer would cause it to become effectively COPY-ALL-LEVELS, whereas
a modest integer would allow one to partially copy circular structures.

  Name             Action on PAIR "x"          Action on VECTOR "x"
-----------------|---------------------------|---------------------------------
 COPY1           | (cons (car x) (cdr x))    | (vector-fill (make-vector 
                 |                           |               (vector-length x))
                 |                           |              x)
 COPY-SEQUENCE   | (mapcar #'COPY1 x)        | (mapf VECTOR VECTOR #'COPY1 x)
 COPY*           | (subst () () x)           | (mapf VECTOR VECTOR #'COPY* x)