[Top][All Lists]

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

Re: Generic sequences in seq.el

From: Stefan Monnier
Subject: Re: Generic sequences in seq.el
Date: Fri, 21 Dec 2018 09:24:05 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

>     (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)).


reply via email to

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