GNU bug report logs -
#68863
Add support for using setf with seq-subseq
Previous Next
Full log
Message #29 received at 68863 <at> debbugs.gnu.org (full text, mbox):
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.