emacs-devel
[Top][All Lists]
Advanced

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

Re: Generic sequences in seq.el


From: Yuan Fu
Subject: Re: Generic sequences in seq.el
Date: Sat, 22 Dec 2018 21:04:59 -0500

>   (seq-concatenate 'list (seq-subseq seq 0 n)
>                          (list element)
>                          (seq-subseq seq n))

That returns a list, not the sequence. So inserting something into the sequence
makes it not a sequence anymore?

We currently don't have any data-structure that can be efficiently
> modified in-place via push/pop (note that even lists don't qualify
> because push/pop doesn't modify the list in place: they replace a list
> with another without modifying any existing list (unless the PLACE is
> the car/cdr of a list, of course, but that's a separate issue)).

Thanks, it's good to know.

Yuan.

On Fri, Dec 21, 2018 at 9:24 AM Stefan Monnier <address@hidden> wrote:
>     (setf (nthcdr n seq) (cons element (nthcdr n seq)))
> to insert element into the nth position in seq

I think with `seq` you'd do something like

   (seq-concatenate 'list (seq-subseq seq 0 n)
                          (list element)
                          (seq-subseq seq n))

Of course, it's different because it's non-destructive, but insertion
into an array can't be done non-destructively anyway.

> The idea is I'll implement this function for the generic sequence
> that I'll define in the future. Is that a correct approach?
> Other destructive functions that I couldn't find alternatives are delete,
> push, pop, etc.

We currently don't have any data-structure that can be efficiently
modified in-place via push/pop (note that even lists don't qualify
because push/pop doesn't modify the list in place: they replace a list
with another without modifying any existing list (unless the PLACE is
the car/cdr of a list, of course, but that's a separate issue)).


        Stefan



reply via email to

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