[Top][All Lists]

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

Re: If records are not sequences, why does aref work on records?

From: Clément Pit-Claudel
Subject: Re: If records are not sequences, why does aref work on records?
Date: Sat, 8 Apr 2017 08:24:11 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

On 2017-04-08 07:34, Philipp Stephani wrote:
> While the manual mentions that vectors or lists are used, it doesn't 
> say that the sequence functions can simply be used.

It doesn't need to: since vectors and lists are used, it's natural to use 
vector and list functions on these objects.  It goes further: the cl-struct 
predicates are explicitly *documented* to work fine on vectors:

     Given any Lisp object X, ‘(person-p X)’ returns true if X looks
     like a ‘person’, and false otherwise.  (Again, in Common Lisp this
     predicate would be exact; in Emacs Lisp the best it can do is
     verify that X is a vector of the correct length that starts with
     the correct tag symbol.)

… and the :type predicate says:

    Vectors are used by
    default, but ‘(:type list)’ will cause structure objects to be
    stored as lists instead.

… and of course, until the changes discussed here, cl-defstructs were printed 
just like vectors.

> Rather, the implementation as sequence is an implementation detail
> that users shouldn't rely on.

The manual doesn't say that — I don't think it's fair to call "implementation 
detail" something that's documented and explicitly not described as an 
implementation detail:

    Since the underlying Emacs Lisp system
    provides no way to create new distinct types, this package implements
    structures as vectors (or lists upon request) with a special “tag”
    symbol to identify them.

> cl-defstruct even creates a copy-FOO function to copy structures,
> which should be used instead of copy-sequence. Therefore, I think
> it's fine to not allow copy-sequence and aref on structure types any
> more, if this change is properly documented.

Please, let's not break perfectly working code gratuitously.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]