mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-12-26 10:49:33 +00:00
Deprecate copy-record in favor of copy-sequence
Since copy-sequence seems to be needed anyway for records, have it work on records, and remove copy-record as being superfluous. * doc/lispref/records.texi (Records, Record Functions): * lisp/emacs-lisp/cl-macs.el (cl-defstruct): * lisp/emacs-lisp/eieio.el (make-instance, clone): * test/src/alloc-tests.el (record-3): Use copy-sequence, not copy-record, to copy records. * doc/lispref/sequences.texi (Sequence Functions) (Array Functions): Document that aref and copy-sequence work on records. * etc/NEWS: Omit copy-record. * src/alloc.c (Fcopy_record): Remove. * src/data.c (Faref): Document that arg can be a record. * src/fns.c (Fcopy_sequence): Copy records, too.
This commit is contained in:
parent
a614cd416c
commit
a2b3fea957
@ -13,8 +13,9 @@ underlying representation of @code{cl-defstruct} and @code{defclass}
|
||||
instances.
|
||||
|
||||
Internally, a record object is much like a vector; its slots can be
|
||||
accessed using @code{aref}. However, the first slot is used to hold
|
||||
its type as returned by @code{type-of}. Also, in the current
|
||||
accessed using @code{aref} and it can be copied using
|
||||
@code{copy-sequence}. However, the first slot is used to hold its
|
||||
type as returned by @code{type-of}. Also, in the current
|
||||
implementation records can have at most 4096 slots, whereas vectors
|
||||
can be much larger. Like arrays, records use zero-origin indexing:
|
||||
the first slot has index 0.
|
||||
@ -74,38 +75,6 @@ This function returns a new record with type @var{type} and
|
||||
@end example
|
||||
@end defun
|
||||
|
||||
@defun copy-record record
|
||||
This function returns a shallow copy of @var{record}. The copy is the
|
||||
same type as the original record, and it has the same slots in the
|
||||
same order.
|
||||
|
||||
Storing a new slot into the copy does not affect the original
|
||||
@var{record}, and vice versa. However, the slots of the new record
|
||||
are not copies; they are identical (@code{eq}) to the slots of the
|
||||
original. Therefore, changes made within these slots, as found via
|
||||
the copied record, are also visible in the original record.
|
||||
|
||||
@example
|
||||
@group
|
||||
(setq x (record 'foo 1 2))
|
||||
@result{} #s(foo 1 2)
|
||||
@end group
|
||||
@group
|
||||
(setq y (copy-record x))
|
||||
@result{} #s(foo 1 2)
|
||||
@end group
|
||||
|
||||
@group
|
||||
(eq x y)
|
||||
@result{} nil
|
||||
@end group
|
||||
@group
|
||||
(equal x y)
|
||||
@result{} t
|
||||
@end group
|
||||
@end example
|
||||
@end defun
|
||||
|
||||
@node Backward Compatibility
|
||||
@section Backward Compatibility
|
||||
|
||||
|
@ -151,20 +151,19 @@ This function generalizes @code{aref} (@pxref{Array Functions}) and
|
||||
@code{nth} (@pxref{Definition of nth}).
|
||||
@end defun
|
||||
|
||||
@defun copy-sequence sequence
|
||||
@defun copy-sequence seqr
|
||||
@cindex copying sequences
|
||||
This function returns a copy of @var{sequence}. The copy is the same
|
||||
type of object as the original sequence, and it has the same elements
|
||||
in the same order.
|
||||
This function returns a copy of @var{seqr}, which should be either a
|
||||
sequence or a record. The copy is the same type of object as the
|
||||
original, and it has the same elements in the same order.
|
||||
|
||||
Storing a new element into the copy does not affect the original
|
||||
@var{sequence}, and vice versa. However, the elements of the new
|
||||
sequence are not copies; they are identical (@code{eq}) to the elements
|
||||
@var{seqr}, and vice versa. However, the elements of the copy
|
||||
are not copies; they are identical (@code{eq}) to the elements
|
||||
of the original. Therefore, changes made within these elements, as
|
||||
found via the copied sequence, are also visible in the original
|
||||
sequence.
|
||||
found via the copy, are also visible in the original.
|
||||
|
||||
If the sequence is a string with text properties, the property list in
|
||||
If the argument is a string with text properties, the property list in
|
||||
the copy is itself a copy, not shared with the original's property
|
||||
list. However, the actual values of the properties are shared.
|
||||
@xref{Text Properties}.
|
||||
@ -1148,10 +1147,10 @@ vector, a string, a bool-vector or a char-table).
|
||||
@end example
|
||||
@end defun
|
||||
|
||||
@defun aref array index
|
||||
@defun aref arr index
|
||||
@cindex array elements
|
||||
This function returns the @var{index}th element of @var{array}. The
|
||||
first element is at index zero.
|
||||
This function returns the @var{index}th element of the array or record
|
||||
@var{arr}. The first element is at index zero.
|
||||
|
||||
@example
|
||||
@group
|
||||
|
6
etc/NEWS
6
etc/NEWS
@ -863,9 +863,9 @@ instead of its first.
|
||||
|
||||
+++
|
||||
** Emacs now supports records for user-defined types, via the new
|
||||
functions 'copy-record', 'make-record', 'record', and 'recordp'.
|
||||
Records are now used internally to represent cl-defstruct and defclass
|
||||
instances, for example.
|
||||
functions 'make-record', 'record', and 'recordp'. Records are now
|
||||
used internally to represent cl-defstruct and defclass instances, for
|
||||
example.
|
||||
|
||||
+++
|
||||
** 'save-some-buffers' now uses 'save-some-buffers-default-predicate'
|
||||
|
@ -2808,8 +2808,7 @@ non-nil value, that slot cannot be set via `setf'.
|
||||
(setq slots (nreverse slots)
|
||||
defaults (nreverse defaults))
|
||||
(and copier
|
||||
(push `(defalias ',copier
|
||||
,(if (null type) '#'copy-record '#'copy-sequence))
|
||||
(push `(defalias ',copier #'copy-sequence)
|
||||
forms))
|
||||
(if constructor
|
||||
(push (list constructor
|
||||
|
@ -699,8 +699,8 @@ SLOTS are the initialization slots used by `initialize-instance'.
|
||||
This static method is called when an object is constructed.
|
||||
It allocates the vector used to represent an EIEIO object, and then
|
||||
calls `initialize-instance' on that object."
|
||||
(let* ((new-object (copy-record (eieio--class-default-object-cache
|
||||
(eieio--class-object class)))))
|
||||
(let* ((new-object (copy-sequence (eieio--class-default-object-cache
|
||||
(eieio--class-object class)))))
|
||||
(if (and slots
|
||||
(let ((x (car slots)))
|
||||
(or (stringp x) (null x))))
|
||||
@ -804,7 +804,7 @@ first and modify the returned object.")
|
||||
|
||||
(cl-defmethod clone ((obj eieio-default-superclass) &rest params)
|
||||
"Make a copy of OBJ, and then apply PARAMS."
|
||||
(let ((nobj (copy-record obj)))
|
||||
(let ((nobj (copy-sequence obj)))
|
||||
(if (stringp (car params))
|
||||
(funcall (if eieio-backward-compatibility #'ignore #'message)
|
||||
"Obsolete name %S passed to clone" (pop params)))
|
||||
|
14
src/alloc.c
14
src/alloc.c
@ -3440,19 +3440,6 @@ usage: (record TYPE &rest SLOTS) */)
|
||||
}
|
||||
|
||||
|
||||
DEFUN ("copy-record", Fcopy_record, Scopy_record, 1, 1, 0,
|
||||
doc: /* Return a new record that is a shallow copy of the argument RECORD. */)
|
||||
(Lisp_Object record)
|
||||
{
|
||||
CHECK_RECORD (record);
|
||||
ptrdiff_t size = ASIZE (record) & PSEUDOVECTOR_SIZE_MASK;
|
||||
struct Lisp_Vector *new = allocate_record (size);
|
||||
memcpy (new->contents, XVECTOR (record)->contents,
|
||||
size * sizeof (Lisp_Object));
|
||||
return make_lisp_ptr (new, Lisp_Vectorlike);
|
||||
}
|
||||
|
||||
|
||||
DEFUN ("make-vector", Fmake_vector, Smake_vector, 2, 2, 0,
|
||||
doc: /* Return a newly created vector of length LENGTH, with each element being INIT.
|
||||
See also the function `vector'. */)
|
||||
@ -7523,7 +7510,6 @@ The time is in seconds as a floating point value. */);
|
||||
defsubr (&Slist);
|
||||
defsubr (&Svector);
|
||||
defsubr (&Srecord);
|
||||
defsubr (&Scopy_record);
|
||||
defsubr (&Sbool_vector);
|
||||
defsubr (&Smake_byte_code);
|
||||
defsubr (&Smake_list);
|
||||
|
@ -2266,8 +2266,8 @@ function chain of symbols. */)
|
||||
/* Extract and set vector and string elements. */
|
||||
|
||||
DEFUN ("aref", Faref, Saref, 2, 2, 0,
|
||||
doc: /* Return the element of ARRAY at index IDX.
|
||||
ARRAY may be a vector, a string, a char-table, a bool-vector,
|
||||
doc: /* Return the element of ARG at index IDX.
|
||||
ARG may be a vector, a string, a char-table, a bool-vector, a record,
|
||||
or a byte-code object. IDX starts at 0. */)
|
||||
(register Lisp_Object array, Lisp_Object idx)
|
||||
{
|
||||
|
12
src/fns.c
12
src/fns.c
@ -475,13 +475,19 @@ usage: (vconcat &rest SEQUENCES) */)
|
||||
|
||||
|
||||
DEFUN ("copy-sequence", Fcopy_sequence, Scopy_sequence, 1, 1, 0,
|
||||
doc: /* Return a copy of a list, vector, string or char-table.
|
||||
The elements of a list or vector are not copied; they are shared
|
||||
with the original. */)
|
||||
doc: /* Return a copy of a list, vector, string, char-table or record.
|
||||
The elements of a list, vector or record are not copied; they are
|
||||
shared with the original. */)
|
||||
(Lisp_Object arg)
|
||||
{
|
||||
if (NILP (arg)) return arg;
|
||||
|
||||
if (RECORDP (arg))
|
||||
{
|
||||
ptrdiff_t size = ASIZE (arg) & PSEUDOVECTOR_SIZE_MASK;
|
||||
return Frecord (size, XVECTOR (arg)->contents);
|
||||
}
|
||||
|
||||
if (CHAR_TABLE_P (arg))
|
||||
{
|
||||
return copy_char_table (arg);
|
||||
|
@ -47,7 +47,7 @@
|
||||
|
||||
(ert-deftest record-3 ()
|
||||
(let* ((x (record 'foo 1 2 3))
|
||||
(y (copy-record x)))
|
||||
(y (copy-sequence x)))
|
||||
(should-not (eq x y))
|
||||
(dotimes (i 4)
|
||||
(should (eql (aref x i) (aref y i))))))
|
||||
|
Loading…
Reference in New Issue
Block a user