From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.devel Subject: Re: Generic sequences in seq.el Date: Sat, 22 Dec 2018 21:04:59 -0500 Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000f7f89f057da6e8d2" X-Trace: blaine.gmane.org 1545530601 30270 195.159.176.226 (23 Dec 2018 02:03:21 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 23 Dec 2018 02:03:21 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Dec 23 03:03:17 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gat6r-0007lu-Ct for ged-emacs-devel@m.gmane.org; Sun, 23 Dec 2018 03:03:17 +0100 Original-Received: from localhost ([::1]:49059 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gat8y-0004mm-1M for ged-emacs-devel@m.gmane.org; Sat, 22 Dec 2018 21:05:28 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50374) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gat8j-0004l4-D0 for emacs-devel@gnu.org; Sat, 22 Dec 2018 21:05:14 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gat8i-0007JY-9w for emacs-devel@gnu.org; Sat, 22 Dec 2018 21:05:13 -0500 Original-Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]:37509) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gat8i-0007HR-1q for emacs-devel@gnu.org; Sat, 22 Dec 2018 21:05:12 -0500 Original-Received: by mail-lf1-x12a.google.com with SMTP id y11so6395208lfj.4 for ; Sat, 22 Dec 2018 18:05:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=IDD+UeeiwfOpm9yoFCDQEYjVQT/naYgt1kqSKN15cKo=; b=qgwYKahI6CHJGEYJJ0ONv3nRr9sNN+OblGrf95Ukkq+O9w+90aPuLT6xac8P+l1EwN VjzFt1FEnjscV+yaWkl743b8u5w1o48UKuR42mFBNDpBQJfHoMBm/O+m9ZbyVrBV3TUX RJIE2mxIGIK2gaPpruZzDQpGxPIObxy0GhCCwcIhFKUVNl2k2Ymx6FhW+8EnmrBwKYIG fTJ3/4+ocQlKOp3pOGRmStmdGjlhzJY48vNn81ZBUahTRHRMEzQNcGdkGrwPXAFhVhvy eyUd8LaU/6nGv5mHey2W12I0a8C4Nwwj/WL918MAbt6usdTB7CKjnuoMSEOk7nzCY/w0 +X9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=IDD+UeeiwfOpm9yoFCDQEYjVQT/naYgt1kqSKN15cKo=; b=js43nVdzioCMSi6Wvs/kDMM0VQTTFGGBCgTnVVOjaX47eYpxA05ANC0wuw8t5Aard6 5NFij92oxC1qaUeyFGSlwEz3HkkeBDovGeBjavwKNno64qvnhO9CVWXjrQ7Hb0/6yjd8 si5ZfimgxfTJgbdKwm4RY3+IDySkM1IDmM52D/g3BrqEEzwwITnK59GpWY5k8B6nlsEe BrmX7n0KBB1HcWs8YzncZzQJznBORrfRCqtohf3kCYkOtAGWnQaEaFcQGPKNeFDrvsgw P4i0WabkX/f+zIwgTH+a7Dq3B8UocuWEfuGhxFPS3xXXGXQBpg7/Qn4wsuSlwocqeZ/Y KHMQ== X-Gm-Message-State: AA+aEWYohUaL5/70267BkJxrTCr0TuPcyPsjygJ8NHMuc0SNAPpc93DZ KsrIG/GBaRZ5Ih4WN3nQj4JR+HyDJlrLLMCyTyw= X-Google-Smtp-Source: AFSGD/Wz5TJ3lSa4fElt2MZggr4RgE94bI2svZDJ4gqEXmYZibrK8b7hNYSsFDUEH1mjzT98zJV/LUkOpflVlkmuIuw= X-Received: by 2002:a19:1994:: with SMTP id 142mr4392409lfz.134.1545530710160; Sat, 22 Dec 2018 18:05:10 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::12a X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:231962 Archived-At: --000000000000f7f89f057da6e8d2 Content-Type: text/plain; charset="UTF-8" > (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 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 > > > --000000000000f7f89f057da6e8d2 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
>=C2=A0 =C2=A0(seq-concatenate 'list (seq-subseq seq 0 n)=
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (list elemen= t)=
>= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 (seq-subseq seq n))

That returns a list, not the s= equence. So inserting something into the sequence
<= span style=3D"color:rgb(0,0,0)">makes it not a sequence anymore?
=

>=C2=A0We curren= tly don't have any data-structure that can be efficiently
<= span style=3D"color:rgb(0,0,0)">> modified in-place via push/pop (note tha= t even lists don't qualify
> because push/pop doesn't modify the list i= n 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 separa= te issue)).

Thanks, it's good to know.

Yuan= .

= On Fri, Dec 21, 2018 at 9:24 AM Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>=C2=A0 =C2=A0 =C2=A0(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

=C2=A0 =C2=A0(seq-concatenate 'list (seq-subseq seq 0 n)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 (list element)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 (seq-subseq seq n))

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

> The idea is I'll implement this function for the generic sequence<= br> > 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<= br> 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)).


=C2=A0 =C2=A0 =C2=A0 =C2=A0 Stefan


--000000000000f7f89f057da6e8d2--