GNU bug report logs - #68863
Add support for using setf with seq-subseq

Previous Next

Package: emacs;

Reported by: Okamsn <okamsn <at> protonmail.com>

Date: Thu, 1 Feb 2024 03:32:02 UTC

Severity: wishlist

Full log


Message #29 received at 68863 <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Okamsn <okamsn <at> protonmail.com>
Cc: 68863 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>,
 Nicolas Petton <nicolas <at> petton.fr>, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#68863: Add support for using setf with seq-subseq
Date: Wed, 08 May 2024 23:01:22 +0200
Okamsn <okamsn <at> protonmail.com> writes:

> Subject: [PATCH v2] Add setf support for seq-subseq.

Thank you for the update.

I wonder about the implementation for listp STOREs:

> +(cl-defmethod (setf seq-subseq) (store (sequence list) start &optional end)
> +  "Modify the elements of SEQUENCE from START to END to be those of STORE.
> +END is exclusive.
> +
> +If END is omitted, it defaults to the length of the sequence.  If
> +START or END is negative, it counts from the end. [...]

In the case where we don't count from the end:

> +error if START or END are outside of the sequence (i.e too large
> +if positive or too small if negative).
> +
> +SEQUENCE is neither lengthened nor shortened."
> +  (let* ((len (seq-length sequence))

running through the complete list just to get its length which we don't
need is a waste of time - right?

> +      (catch tag
> +        (seq-do (let ((replaced (nthcdr idx sequence)))
> +                  (lambda (v)
> +                    (if (< idx idx-end)
> +                        (setf (car replaced) v
> +                              replaced (cdr replaced)
> +                              idx (1+ idx))
> +                      (throw tag nil))))
> +                store))))
> +  store)

And wouldn't it here be more efficient to use `setcar' and `setcdr'
manipulations to insert the complete sequence (if it's a list, else we
may convert it into one) in one go instead of replacing elements one by
one?


Thanks,

Michael.




This bug report was last modified 107 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.