From unknown Tue Jun 17 01:28:22 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#56521 <56521@debbugs.gnu.org> To: bug#56521 <56521@debbugs.gnu.org> Subject: Status: Add 'take' list operation [PATCH] Reply-To: bug#56521 <56521@debbugs.gnu.org> Date: Tue, 17 Jun 2025 08:28:22 +0000 retitle 56521 Add 'take' list operation [PATCH] reassign 56521 emacs submitter 56521 Mattias Engdeg=C3=A5rd severity 56521 wishlist tag 56521 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Tue Jul 12 13:06:09 2022 Received: (at submit) by debbugs.gnu.org; 12 Jul 2022 17:06:09 +0000 Received: from localhost ([127.0.0.1]:43621 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oBJKq-0000b0-OU for submit@debbugs.gnu.org; Tue, 12 Jul 2022 13:06:09 -0400 Received: from lists.gnu.org ([209.51.188.17]:48590) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oBJKp-0000at-7y for submit@debbugs.gnu.org; Tue, 12 Jul 2022 13:06:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37898) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBJKo-0002El-RR for bug-gnu-emacs@gnu.org; Tue, 12 Jul 2022 13:06:07 -0400 Received: from mail1458c50.megamailservers.eu ([91.136.14.58]:52222 helo=mail267c50.megamailservers.eu) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBJKk-0004os-FL for bug-gnu-emacs@gnu.org; Tue, 12 Jul 2022 13:06:06 -0400 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1657645557; bh=vS93sYYyH9x3Z5xFXIkNJswT99C0otjcw+R+/vsq4o0=; h=From:Subject:Date:To:From; b=iPsewlJ3sprN0pBdQXT5HsMtFNxxDKmDyI9TifuarTT5ikHVLZ1Tl6MpkXSS2efLO UeOQ+DNR6m/yqMSFGhvr+6oeGvz8B1++mzYuNJetyEmptfWvq/Zwif7m57eCulSHNp uhZT+GyojXf6XpAos/NEdWNEh/AHryHfAsVNYzuc= Feedback-ID: mattiase@acm.or Received: from smtpclient.apple (c188-150-171-71.bredband.tele2.se [188.150.171.71]) (authenticated bits=0) by mail267c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id 26CH5tIg031085 for ; Tue, 12 Jul 2022 17:05:56 +0000 From: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= Content-Type: multipart/mixed; boundary="Apple-Mail=_8A2BAA01-BD0D-460B-B0D2-4BE62F9223DF" Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Subject: Add 'take' list operation [PATCH] Message-Id: <3D32AB50-DC48-4AAE-831C-DDAC6225DFCF@acm.org> Date: Tue, 12 Jul 2022 19:05:54 +0200 To: bug-gnu-emacs@gnu.org X-Mailer: Apple Mail (2.3654.120.0.1.13) X-CTCH-RefID: str=0001.0A782F1A.62CDA9F5.001C, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-CTCH-VOD: Unknown X-CTCH-Spam: Unknown X-CTCH-Score: 0.000 X-CTCH-Rules: X-CTCH-Flags: 0 X-CTCH-ScoreCust: 0.000 X-Origin-Country: SE Received-SPF: softfail client-ip=91.136.14.58; envelope-from=mattiase@acm.org; helo=mail267c50.megamailservers.eu X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) --Apple-Mail=_8A2BAA01-BD0D-460B-B0D2-4BE62F9223DF Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii A basic list operation that is often useful is 'take', that extracts the = N first elements of a list. The attached patch adds 'take' as a built-in = function. We already have its complement, `drop`, under the name `nthcdr`. (I = wouldn't mind adding `drop` as an alias but it's not very important.) How would it compare to existing alternatives, or to a pure Lisp = implementation? Here are relative timings (smaller is better), sans GC. N/M means taking N elements from a list of M. | | 5/10 | 9999/10000 | 1/10 | 1/0 | |------------+------+------------+------+------| | take | 1.00 | 1.00 | 1.00 | 1.00 | |------------+------+------------+------+------| | seq-take | 4.90 | 3.45 | 5.82 | 4.95 | | -take | 4.01 | 4.92 | 2.86 | 1.54 | |------------+------+------------+------+------| | fwd | 2.89 | 3.76 | 1.77 | 1.25 | | rev | 2.90 | 3.45 | 2.06 | 1.38 | | cl-loop | 3.18 | 3.82 | 2.21 | 1.65 | | butlast | 3.58 | 1.73 | 6.59 | 2.33 | |------------+------+------------+------+------| | ntake (el) | 0.80 | 0.20 | 1.51 | 1.40 | | ntake (C) | 0.48 | 0.41 | 0.83 | 0.99 | `seq-take` and `-take` are existing implementations from seq.el and = dash.el respectively. `fwd`, `rev`, `cl-loop` and `butlast` are=20 alternative implementations in elisp. `ntake` are elisp and C = implementations of a destructive take operation A common replacement is using `butlast` but as we see that is very = inefficient (worse than the table suggests since GC costs are not = included). It also doesn't work for circular or dotted lists. The C implementation would, of course, be used to implement `seq-take` = for lists and speed up existing code.=20 Adding `ntake` as a C primitive is not quite as beneficial since the = elisp implementation does fairly well. (I'm not sure why Elisp is = actually faster than C in the 9999/10000 case; maybe I made a mistake, = or it has something to do with `nthcdr` having its own bytecode). I = included `ntake` in the patch for reference and because it's Lisp = tradition to have faster destructive 'n-' variants of list functions. The patch is just a draft; there will be tests and manual text. There are details that can be debated. For example, we don't error on = negative N. It might be useful to allow the compiler to partially = evaluate calls where N<2 or LIST=3Dnil. --Apple-Mail=_8A2BAA01-BD0D-460B-B0D2-4BE62F9223DF Content-Disposition: attachment; filename=take.diff Content-Type: application/octet-stream; x-unix-mode=0644; name="take.diff" Content-Transfer-Encoding: quoted-printable diff=20--git=20a/src/fns.c=20b/src/fns.c=0Aindex=20= 1f57e675b1..2f507573a1=20100644=0A---=20a/src/fns.c=0A+++=20b/src/fns.c=0A= @@=20-1557,6=20+1557,61=20@@=20substring_both=20(Lisp_Object=20string,=20= ptrdiff_t=20from,=20ptrdiff_t=20from_byte,=0A=20=20=20return=20res;=0A=20= }=0A=20=0C=0A+DEFUN=20("take",=20Ftake,=20Stake,=202,=202,=200,=0A+=20=20= =20=20=20=20=20doc:=20/*=20Return=20the=20first=20N=20elements=20of=20= LIST.=0A+If=20N=20is=20zero=20or=20negative,=20return=20nil.=0A+If=20= LIST=20is=20not=20more=20than=20N=20elements=20long,=20return=20it=20(or=20= a=20copy).=20=20*/)=0A+=20=20(Lisp_Object=20n,=20Lisp_Object=20list)=0A= +{=0A+=20=20CHECK_FIXNUM=20(n);=0A+=20=20EMACS_INT=20m=20=3D=20XFIXNUM=20= (n);=0A+=20=20if=20(m=20<=3D=200)=0A+=20=20=20=20return=20Qnil;=0A+=20=20= CHECK_LIST=20(list);=0A+=20=20if=20(NILP=20(list))=0A+=20=20=20=20return=20= Qnil;=0A+=20=20Lisp_Object=20ret=20=3D=20Fcons=20(XCAR=20(list),=20= Qnil);=0A+=20=20Lisp_Object=20prev=20=3D=20ret;=0A+=20=20m--;=0A+=20=20= list=20=3D=20XCDR=20(list);=0A+=20=20while=20(m=20>=200=20&&=20CONSP=20= (list))=0A+=20=20=20=20{=0A+=20=20=20=20=20=20Lisp_Object=20p=20=3D=20= Fcons=20(XCAR=20(list),=20Qnil);=0A+=20=20=20=20=20=20XSETCDR=20(prev,=20= p);=0A+=20=20=20=20=20=20prev=20=3D=20p;=0A+=20=20=20=20=20=20m--;=0A+=20= =20=20=20=20=20list=20=3D=20XCDR=20(list);=0A+=20=20=20=20}=0A+=20=20if=20= (m=20>=200=20&&=20!NILP=20(list))=0A+=20=20=20=20wrong_type_argument=20= (Qlistp,=20list);=0A+=20=20return=20ret;=0A+}=0A+=0A+DEFUN=20("ntake",=20= Fntake,=20Sntake,=202,=202,=200,=0A+=20=20=20=20=20=20=20doc:=20/*=20= Return=20the=20first=20N=20elements=20of=20LIST,=20destructively.=0A+If=20= N=20is=20zero=20or=20negative,=20return=20nil.=0A+If=20LIST=20is=20not=20= more=20than=20N=20elements=20long,=20return=20it.=20=20*/)=0A+=20=20= (Lisp_Object=20n,=20Lisp_Object=20list)=0A+{=0A+=20=20CHECK_FIXNUM=20= (n);=0A+=20=20EMACS_INT=20m=20=3D=20XFIXNUM=20(n);=0A+=20=20if=20(m=20<=3D= =200)=0A+=20=20=20=20return=20Qnil;=0A+=20=20CHECK_LIST=20(list);=0A+=20=20= Lisp_Object=20tail=20=3D=20list;=0A+=20=20--m;=0A+=20=20while=20(m=20>=20= 0=20&&=20CONSP=20(tail))=0A+=20=20=20=20{=0A+=20=20=20=20=20=20tail=20=3D=20= XCDR=20(tail);=0A+=20=20=20=20=20=20m--;=0A+=20=20=20=20}=0A+=20=20if=20= (CONSP=20(tail))=0A+=20=20=20=20XSETCDR=20(tail,=20Qnil);=0A+=20=20else=20= if=20(!NILP=20(tail))=0A+=20=20=20=20wrong_type_argument=20(Qlistp,=20= list);=0A+=20=20return=20list;=0A+}=0A+=0A=20DEFUN=20("nthcdr",=20= Fnthcdr,=20Snthcdr,=202,=202,=200,=0A=20=20=20=20=20=20=20=20doc:=20/*=20= Take=20cdr=20N=20times=20on=20LIST,=20return=20the=20result.=20=20*/)=0A=20= =20=20(Lisp_Object=20n,=20Lisp_Object=20list)=0A@@=20-6082,6=20+6137,8=20= @@=20syms_of_fns=20(void)=0A=20=20=20defsubr=20(&Scopy_alist);=0A=20=20=20= defsubr=20(&Ssubstring);=0A=20=20=20defsubr=20= (&Ssubstring_no_properties);=0A+=20=20defsubr=20(&Stake);=0A+=20=20= defsubr=20(&Sntake);=0A=20=20=20defsubr=20(&Snthcdr);=0A=20=20=20defsubr=20= (&Snth);=0A=20=20=20defsubr=20(&Selt);=0A= --Apple-Mail=_8A2BAA01-BD0D-460B-B0D2-4BE62F9223DF-- From debbugs-submit-bounces@debbugs.gnu.org Tue Jul 12 18:51:54 2022 Received: (at 56521) by debbugs.gnu.org; 12 Jul 2022 22:51:54 +0000 Received: from localhost ([127.0.0.1]:43857 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oBOjS-0003W2-7q for submit@debbugs.gnu.org; Tue, 12 Jul 2022 18:51:54 -0400 Received: from quimby.gnus.org ([95.216.78.240]:41894) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oBOjB-0003VX-S4 for 56521@debbugs.gnu.org; Tue, 12 Jul 2022 18:51:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID :Date:References:In-Reply-To:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=e83Y3N9kKTHZWD3I+2wFyWo8GOA7wfwyIn+eG96U8sg=; b=D/OTwy5XiIRmjPd1PsEwQWglwp Ecs8H9UrzrCh221MwoIHpVduiFkr839xb+drZpfIzBdp3FLJZPEx5GXFb3Znmiz2nLZ9hjWk92eax 1CKpFx3BipfytBrUXWKkYwagBfZKGKPCDR14oSuxQY2UfDJJVc9LToQCuA3LHlxBHu1c=; Received: from [84.212.220.105] (helo=joga) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oBOj2-0004T5-HG; Wed, 13 Jul 2022 00:51:31 +0200 From: Lars Ingebrigtsen To: Mattias =?utf-8?Q?Engdeg=C3=A5rd?= Subject: Re: bug#56521: Add 'take' list operation [PATCH] In-Reply-To: <3D32AB50-DC48-4AAE-831C-DDAC6225DFCF@acm.org> ("Mattias =?utf-8?Q?Engdeg=C3=A5rd=22's?= message of "Tue, 12 Jul 2022 19:05:54 +0200") References: <3D32AB50-DC48-4AAE-831C-DDAC6225DFCF@acm.org> X-Now-Playing: Autechre's _Plus_: "ecol4" Date: Wed, 13 Jul 2022 00:51:28 +0200 Message-ID: <878royueq7.fsf@gnus.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: Mattias EngdegÄrd writes: > A basic list operation that is often useful is 'take', that extracts > the N first elements of a list. The attached patch adds 'take' as a > built-in function. Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 56521 Cc: 56521@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Mattias Engdeg=C3=A5rd writes: > A basic list operation that is often useful is 'take', that extracts > the N first elements of a list. The attached patch adds 'take' as a > built-in function. I'm not against adding this, but I'm not sure of the utility. That is, if you have performance critical code, you don't use `take', because it generates much garbage -- instead you loop over a list, taking the elements a few at a time explicitly. And if you don't have performance critical code, then why not use `seq-take'? So a fast `take' seems to me to land in that uncanny zone of "you don't really need that", but there may, of course, be usage scenarios that I'm not aware of. > I included `ntake` in the patch for reference and because it's Lisp > tradition to have faster destructive 'n-' variants of list functions. I think `ntake' would be a more popular function than `take', really -- because shortening a list is efficient, and something that's not uncommon to do, and it's a bother to write (setcdr (nthcdr 10 list) nil) especially since that may bug out if the list is shorter. But as you say, the Lisp version of ntake may well be faster than the C version, so perhaps just stick it in subr.el instead? But I'm not sure about the `ntake' name. =F0=9F=98=80 It's natural in one= way, but since the main point is that the list is shortened, then perhaps `list-shorten' (or something like that) is more appropriate. --=20 (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no From debbugs-submit-bounces@debbugs.gnu.org Wed Jul 13 07:46:28 2022 Received: (at control) by debbugs.gnu.org; 13 Jul 2022 11:46:28 +0000 Received: from localhost ([127.0.0.1]:44716 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oBap1-0003TH-Pe for submit@debbugs.gnu.org; Wed, 13 Jul 2022 07:46:28 -0400 Received: from mail-pj1-f43.google.com ([209.85.216.43]:51882) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oBap0-0003Na-9a for control@debbugs.gnu.org; Wed, 13 Jul 2022 07:46:26 -0400 Received: by mail-pj1-f43.google.com with SMTP id o15so11646788pjh.1 for ; Wed, 13 Jul 2022 04:46:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:mime-version:date:message-id:subject:to; bh=5GDC6ppJL9Mk9NPUUuHmt5oa2RYeH2j8RWc/v8rCPyQ=; b=BYQEXbdYUyJFmUp9q45euKsPFkj2XS6h6EP4fRvCN3xZ4zBPBbVr7aTI0DmSg1TJPv zx1vEYg35/WjrZIGG4mzu30HlIWQ7w7WpJD5nt+eVTbjj/ANh+ArVc8HTz9t3P6FxYSs Am7VVmOSpWi/BHR9S6omCceM+9Y9Z0jmlF0alQzbjI6WGY26HoYeBGI3swCeCk1U49aT Gjp779pTh44EgyjDQgjoHABnJiN4HumD1iKWZ8hPpEBqmLm5Q9Y9WbgrcBty94OoWuc/ G5qrutt0EXvtoqFlKqmsH9HylG10Yh+qh0HTyo5IJYJpFhKkaQLafu/2MJhzMPRdIccZ hPpg== X-Gm-Message-State: AJIora+i7nCWLv4rG2R5RhmYuz8RjaspgHpmDJ0OQVjEb56ao97vVjgA DG2Bd2VsXjLJavQ77FsFoOS0TcvizJ1imbwv8RuABqYf X-Google-Smtp-Source: AGRyM1t0Q1NBNVQMjVt9iPE+21nBA6vO9G3382kF9d3motsobOz0w+BFNxYiimGj1mHltdAxwzssPqauZo+4yMDbBeI= X-Received: by 2002:a17:90b:4f85:b0:1f0:95d:c02b with SMTP id qe5-20020a17090b4f8500b001f0095dc02bmr9646356pjb.89.1657712780452; Wed, 13 Jul 2022 04:46:20 -0700 (PDT) Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Wed, 13 Jul 2022 04:46:20 -0700 From: Stefan Kangas MIME-Version: 1.0 Date: Wed, 13 Jul 2022 04:46:20 -0700 Message-ID: Subject: control message for bug #56521 To: control@debbugs.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.5 (/) severity 56521 wishlist quit From debbugs-submit-bounces@debbugs.gnu.org Wed Jul 13 09:18:52 2022 Received: (at 56521) by debbugs.gnu.org; 13 Jul 2022 13:18:52 +0000 Received: from localhost ([127.0.0.1]:45046 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oBcGR-0007E9-T0 for submit@debbugs.gnu.org; Wed, 13 Jul 2022 09:18:52 -0400 Received: from mail1469c50.megamailservers.eu ([91.136.14.69]:56420 helo=mail102c50.megamailservers.eu) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oBcGQ-0007Du-4q for 56521@debbugs.gnu.org; Wed, 13 Jul 2022 09:18:51 -0400 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1657718323; bh=0aWX5GM8Zej85aCqQ2S47sMPireOzvKHFGQo7xn2G2c=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=m4mO1DHvh/5iHTDf1C6yuLm8zKbs+oYf+ryJZ2USPP4OZN6F13mPZokxeLcDKNsNP j4FHU1HAL4y1rOmvTaJJiyHoRovY2gKwuJYb84Pq9rx4fUduEEwQL2EQd4lGWGx4y2 PEO5FN2HMIdL+cye8TcG88+JkVnv5xF5Rz2vi8iY= Feedback-ID: mattiase@acm.or Received: from smtpclient.apple (c188-150-171-71.bredband.tele2.se [188.150.171.71]) (authenticated bits=0) by mail102c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id 26DDIfSr114498; Wed, 13 Jul 2022 13:18:43 +0000 From: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= Message-Id: <71564742-E071-4ABD-B8FF-FD8CCD6079B5@acm.org> Content-Type: multipart/mixed; boundary="Apple-Mail=_BAD05BFC-3342-44F7-B1B3-1EF99C9E8C74" Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Subject: Re: bug#56521: Add 'take' list operation [PATCH] Date: Wed, 13 Jul 2022 15:18:41 +0200 In-Reply-To: <878royueq7.fsf@gnus.org> To: Lars Ingebrigtsen References: <3D32AB50-DC48-4AAE-831C-DDAC6225DFCF@acm.org> <878royueq7.fsf@gnus.org> X-Mailer: Apple Mail (2.3654.120.0.1.13) X-CTCH-RefID: str=0001.0A782F29.62CEC633.0061, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-CTCH-VOD: Unknown X-CTCH-Spam: Unknown X-CTCH-Score: 0.000 X-CTCH-Rules: X-CTCH-Flags: 0 X-CTCH-ScoreCust: 0.000 X-Origin-Country: SE X-Spam-Score: 0.3 (/) X-Debbugs-Envelope-To: 56521 Cc: 56521@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) --Apple-Mail=_BAD05BFC-3342-44F7-B1B3-1EF99C9E8C74 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii 13 juli 2022 kl. 00.51 skrev Lars Ingebrigtsen : > I'm not against adding this, but I'm not sure of the utility. That = is, > if you have performance critical code, you don't use `take', because = it > generates much garbage -- instead you loop over a list, taking the > elements a few at a time explicitly. And if you don't have = performance > critical code, then why not use `seq-take'? Thank you, but it is definitely not the case that performance is either = of utmost importance or not at all. In fact, most code falls between = those extremes. In particular, for elaborate packages such as Magit, = Org, Calc, the byte compiler, many programming modes etc, managing = complexity and correctness matter most but performance isn't = unimportant. Another way of looking at it is that we add `take` for convenience, and = implement it in C for performance. And don't underestimate the utility of `take` itself -- it's far from = always possible or desired to do immediate work on the extracted prefix. = I keep seeing it reimplemented (badly) and have done so several times = myself (also badly). It's also useful in conjunction with drop (nthcdr) since (append (take N = L) (drop N L)) =3D L for all N and L. For example, (take N (drop M L)) returns a sublist; (append (take N L) = (drop M L)) removes a sublist. The primitives are easy to reason about. > But as you > say, the Lisp version of ntake may well be faster than the C version, = so > perhaps just stick it in subr.el instead? After a more careful look, that anomaly was probably just a measurement = fluke. On the whole the C implementation is reliably faster, although = naturally the difference isn't nearly as big as for `take`. > But I'm not sure about the `ntake' name. It follows an established convention and makes it easy for the user to = see the relationship with `take` as well as understand how they differ. (We have practically no list primitive starting with 'list-'; those are = commands that list something.) If you prefer we could name it `destructive-take` or = `take-destructively` but these are annoyingly long, lack precedence, and = are not really better. Attached is a more complete patch, now with tests and documentation = updates. --Apple-Mail=_BAD05BFC-3342-44F7-B1B3-1EF99C9E8C74 Content-Disposition: attachment; filename=0001-Add-take-and-ntake-bug-56521.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-Add-take-and-ntake-bug-56521.patch" Content-Transfer-Encoding: quoted-printable =46rom=20dd18df350bb496aaa06d240b1ae71862a048d82d=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20=3D?UTF-8?q?Mattias=3D20Engdeg=3DC3=3DA5rd?=3D=20= =0ADate:=20Wed,=2013=20Jul=202022=2013:46:52=20+0200=0A= Subject:=20[PATCH]=20Add=20`take`=20and=20`ntake`=20(bug#56521)=0A=0A= These=20are=20useful=20list=20primitives,=20complementary=20to=20= `nthcdr`.=0A=0A*=20src/fns.c=20(Ftake,=20Fntake):=20New.=0A= (syms_of_fns):=20Defsubr=20them.=0A*=20doc/lispref/lists.texi=20(List=20= Elements):=0A*=20lisp/emacs-lisp/shortdoc.el=20(list):=20Document=0A*=20= lisp/emacs-lisp/byte-opt.el=20(side-effect-free-fns,=20pure-fns):=0A= Declare=20`take`=20pure=20and=20side-effect-free.=0A*=20= test/src/fns-tests.el=20(fns-tests--take-ref,=20fns--take-ntake):=0ANew=20= test.=0A---=0A=20doc/lispref/lists.texi=20=20=20=20=20=20|=2029=20= +++++++++++++++++++=0A=20lisp/emacs-lisp/byte-opt.el=20|=20=204=20+--=0A=20= lisp/emacs-lisp/shortdoc.el=20|=20=204=20+++=0A=20src/fns.c=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20|=2057=20= +++++++++++++++++++++++++++++++++++++=0A=20test/src/fns-tests.el=20=20=20= =20=20=20=20|=2049=20+++++++++++++++++++++++++++++++=0A=205=20files=20= changed,=20141=20insertions(+),=202=20deletions(-)=0A=0Adiff=20--git=20= a/doc/lispref/lists.texi=20b/doc/lispref/lists.texi=0Aindex=20= a4f0ba815b..2a9ad1d5e0=20100644=0A---=20a/doc/lispref/lists.texi=0A+++=20= b/doc/lispref/lists.texi=0A@@=20-340,6=20+340,35=20@@=20List=20Elements=0A= =20@end=20example=0A=20@end=20defun=0A=20=0A+@defun=20take=20n=20list=0A= +This=20function=20returns=20the=20@var{n}=20first=20elements=20of=20= @var{list}.=20=20Essentially,=0A+it=20returns=20the=20part=20of=20= @var{list}=20that=20@code{nthcdr}=20skips.=0A+=0A+@code{take}=20returns=20= @var{list}=20if=20it=20is=20shorter=20than=20@var{n}=20elements;=0A+it=20= returns=20@code{nil}=20if=20@var{n}=20is=20zero=20or=20negative.=0A+=0A= +@example=0A+@group=0A+(take=203=20'(a=20b=20c=20d))=0A+=20=20=20=20=20= @result{}=20(a=20b=20c)=0A+@end=20group=0A+@group=0A+(take=2010=20'(a=20= b=20c=20d))=0A+=20=20=20=20=20@result{}=20(a=20b=20c=20d)=0A+@end=20= group=0A+@group=0A+(take=200=20'(a=20b=20c=20d))=0A+=20=20=20=20=20= @result{}=20nil=0A+@end=20group=0A+@end=20example=0A+@end=20defun=0A+=0A= +@defun=20ntake=20n=20list=0A+This=20is=20a=20version=20of=20@code{take}=20= that=20works=20by=20destructively=20modifying=0A+the=20list=20structure=20= of=20the=20argument.=20=20That=20makes=20it=20faster,=20but=20the=0A= +original=20value=20of=20@var{list}=20is=20lost.=0A+@end=20defun=0A+=0A=20= @defun=20last=20list=20&optional=20n=0A=20This=20function=20returns=20= the=20last=20link=20of=20@var{list}.=20=20The=20@code{car}=20of=0A=20= this=20link=20is=20the=20list's=20last=20element.=20=20If=20@var{list}=20= is=20null,=0Adiff=20--git=20a/lisp/emacs-lisp/byte-opt.el=20= b/lisp/emacs-lisp/byte-opt.el=0Aindex=20b7147a7f50..04f766446c=20100644=0A= ---=20a/lisp/emacs-lisp/byte-opt.el=0A+++=20= b/lisp/emacs-lisp/byte-opt.el=0A@@=20-1373,7=20+1373,7=20@@=20= byte-optimize-set=0A=20=09=20symbol-function=20symbol-name=20= symbol-plist=20symbol-value=20string-make-unibyte=0A=20=09=20= string-make-multibyte=20string-as-multibyte=20string-as-unibyte=0A=20=09=20= string-to-multibyte=0A-=09=20tan=20time-convert=20truncate=0A+=09=20take=20= tan=20time-convert=20truncate=0A=20=09=20unibyte-char-to-multibyte=20= upcase=20user-full-name=0A=20=09=20user-login-name=20= user-original-login-name=20custom-variable-p=0A=20=09=20vconcat=0A@@=20= -1449,7=20+1449,7=20@@=20byte-optimize-set=0A=20;;=20values=20if=20a=20= marker=20is=20moved.=0A=20=0A=20(let=20((pure-fns=0A-=20=20=20=20=20=20=20= '(concat=20regexp-opt=20regexp-quote=0A+=20=20=20=20=20=20=20'(concat=20= take=20regexp-opt=20regexp-quote=0A=20=09=20string-to-char=20= string-to-syntax=20symbol-name=0A=20=20=20=20=20=20=20=20=20=20eq=20eql=0A= =20=20=20=20=20=20=20=20=20=20=3D=20/=3D=20<=20<=3D=20>=3D=20>=20min=20= max=0Adiff=20--git=20a/lisp/emacs-lisp/shortdoc.el=20= b/lisp/emacs-lisp/shortdoc.el=0Aindex=20a2d954cadb..1514ece6d1=20100644=0A= ---=20a/lisp/emacs-lisp/shortdoc.el=0A+++=20= b/lisp/emacs-lisp/shortdoc.el=0A@@=20-595,6=20+595,10=20@@=20list=0A=20=20= =20=20:eval=20(nth=201=20'(one=20two=20three)))=0A=20=20=20(nthcdr=0A=20=20= =20=20:eval=20(nthcdr=201=20'(one=20two=20three)))=0A+=20=20(take=0A+=20=20= =20:eval=20(take=203=20'(one=20two=20three=20four)))=0A+=20=20(ntake=0A+=20= =20=20:eval=20(ntake=203=20(list=20'one=20'two=20'three=20'four)))=0A=20=20= =20(elt=0A=20=20=20=20:eval=20(elt=20'(one=20two=20three)=201))=0A=20=20=20= (car-safe=0Adiff=20--git=20a/src/fns.c=20b/src/fns.c=0Aindex=20= 1f57e675b1..84cfec6c3f=20100644=0A---=20a/src/fns.c=0A+++=20b/src/fns.c=0A= @@=20-1557,6=20+1557,61=20@@=20substring_both=20(Lisp_Object=20string,=20= ptrdiff_t=20from,=20ptrdiff_t=20from_byte,=0A=20=20=20return=20res;=0A=20= }=0A=20=0C=0A+DEFUN=20("take",=20Ftake,=20Stake,=202,=202,=200,=0A+=20=20= =20=20=20=20=20doc:=20/*=20Return=20the=20first=20N=20elements=20of=20= LIST.=0A+If=20N=20is=20zero=20or=20negative,=20return=20nil.=0A+If=20= LIST=20is=20no=20more=20than=20N=20elements=20long,=20return=20it=20(or=20= a=20copy).=20=20*/)=0A+=20=20(Lisp_Object=20n,=20Lisp_Object=20list)=0A= +{=0A+=20=20CHECK_FIXNUM=20(n);=0A+=20=20EMACS_INT=20m=20=3D=20XFIXNUM=20= (n);=0A+=20=20if=20(m=20<=3D=200)=0A+=20=20=20=20return=20Qnil;=0A+=20=20= CHECK_LIST=20(list);=0A+=20=20if=20(NILP=20(list))=0A+=20=20=20=20return=20= Qnil;=0A+=20=20Lisp_Object=20ret=20=3D=20Fcons=20(XCAR=20(list),=20= Qnil);=0A+=20=20Lisp_Object=20prev=20=3D=20ret;=0A+=20=20m--;=0A+=20=20= list=20=3D=20XCDR=20(list);=0A+=20=20while=20(m=20>=200=20&&=20CONSP=20= (list))=0A+=20=20=20=20{=0A+=20=20=20=20=20=20Lisp_Object=20p=20=3D=20= Fcons=20(XCAR=20(list),=20Qnil);=0A+=20=20=20=20=20=20XSETCDR=20(prev,=20= p);=0A+=20=20=20=20=20=20prev=20=3D=20p;=0A+=20=20=20=20=20=20m--;=0A+=20= =20=20=20=20=20list=20=3D=20XCDR=20(list);=0A+=20=20=20=20}=0A+=20=20if=20= (m=20>=200=20&&=20!NILP=20(list))=0A+=20=20=20=20wrong_type_argument=20= (Qlistp,=20list);=0A+=20=20return=20ret;=0A+}=0A+=0A+DEFUN=20("ntake",=20= Fntake,=20Sntake,=202,=202,=200,=0A+=20=20=20=20=20=20=20doc:=20/*=20= Modify=20LIST=20to=20keep=20only=20the=20first=20N=20elements.=0A+If=20N=20= is=20zero=20or=20negative,=20return=20nil.=0A+If=20LIST=20is=20no=20more=20= than=20N=20elements=20long,=20return=20it.=20=20*/)=0A+=20=20= (Lisp_Object=20n,=20Lisp_Object=20list)=0A+{=0A+=20=20CHECK_FIXNUM=20= (n);=0A+=20=20EMACS_INT=20m=20=3D=20XFIXNUM=20(n);=0A+=20=20if=20(m=20<=3D= =200)=0A+=20=20=20=20return=20Qnil;=0A+=20=20CHECK_LIST=20(list);=0A+=20=20= Lisp_Object=20tail=20=3D=20list;=0A+=20=20--m;=0A+=20=20while=20(m=20>=20= 0=20&&=20CONSP=20(tail))=0A+=20=20=20=20{=0A+=20=20=20=20=20=20tail=20=3D=20= XCDR=20(tail);=0A+=20=20=20=20=20=20m--;=0A+=20=20=20=20}=0A+=20=20if=20= (CONSP=20(tail))=0A+=20=20=20=20XSETCDR=20(tail,=20Qnil);=0A+=20=20else=20= if=20(!NILP=20(tail))=0A+=20=20=20=20wrong_type_argument=20(Qlistp,=20= list);=0A+=20=20return=20list;=0A+}=0A+=0A=20DEFUN=20("nthcdr",=20= Fnthcdr,=20Snthcdr,=202,=202,=200,=0A=20=20=20=20=20=20=20=20doc:=20/*=20= Take=20cdr=20N=20times=20on=20LIST,=20return=20the=20result.=20=20*/)=0A=20= =20=20(Lisp_Object=20n,=20Lisp_Object=20list)=0A@@=20-6082,6=20+6137,8=20= @@=20syms_of_fns=20(void)=0A=20=20=20defsubr=20(&Scopy_alist);=0A=20=20=20= defsubr=20(&Ssubstring);=0A=20=20=20defsubr=20= (&Ssubstring_no_properties);=0A+=20=20defsubr=20(&Stake);=0A+=20=20= defsubr=20(&Sntake);=0A=20=20=20defsubr=20(&Snthcdr);=0A=20=20=20defsubr=20= (&Snth);=0A=20=20=20defsubr=20(&Selt);=0Adiff=20--git=20= a/test/src/fns-tests.el=20b/test/src/fns-tests.el=0Aindex=20= 20074ca0d2..a84cce3ad4=20100644=0A---=20a/test/src/fns-tests.el=0A+++=20= b/test/src/fns-tests.el=0A@@=20-1365,4=20+1365,53=20@@=20= fns--string-to-unibyte-multibyte=0A=20=20=20(should-error=20= (string-to-unibyte=20"=C3=A5"))=0A=20=20=20(should-error=20= (string-to-unibyte=20"ABC=E2=88=80BC")))=0A=20=0A+(defun=20= fns-tests--take-ref=20(n=20list)=0A+=20=20"Reference=20implementation=20= of=20`take'."=0A+=20=20(named-let=20loop=20((m=20n)=20(tail=20list)=20= (ac=20nil))=0A+=20=20=20=20(if=20(and=20(>=20m=200)=20tail)=0A+=20=20=20=20= =20=20=20=20(loop=20(1-=20m)=20(cdr=20tail)=20(cons=20(car=20tail)=20= ac))=0A+=20=20=20=20=20=20(nreverse=20ac))))=0A+=0A+(ert-deftest=20= fns--take-ntake=20()=0A+=20=20"Test=20`take'=20and=20`ntake'."=0A+=20=20= ;;=20Check=20errors=20and=20edge=20cases.=0A+=20=20(should-error=20(take=20= 'x=20'(a)))=0A+=20=20(should-error=20(ntake=20'x=20'(a)))=0A+=20=20= (should-error=20(take=201=20'a))=0A+=20=20(should-error=20(ntake=201=20= 'a))=0A+=20=20(should-error=20(take=202=20'(a=20.=20b)))=0A+=20=20= (should-error=20(ntake=202=20'(a=20.=20b)))=0A+=20=20;;=20Tolerate=20= non-lists=20for=20a=20count=20of=20zero.=0A+=20=20(should=20(equal=20= (take=200=20'a)=20nil))=0A+=20=20(should=20(equal=20(ntake=200=20'a)=20= nil))=0A+=20=20;;=20But=20not=20non-numbers=20for=20empty=20lists.=0A+=20= =20(should-error=20(take=20'x=20nil))=0A+=20=20(should-error=20(ntake=20= 'x=20nil))=0A+=0A+=20=20(dolist=20(list=20'(nil=20(a)=20(a=20b)=20(a=20b=20= c)=20(a=20b=20c=20d)=20(a=20.=20b)=20(a=20b=20.=20c)))=0A+=20=20=20=20= (ert-info=20((prin1-to-string=20list)=20:prefix=20"list:=20")=0A+=20=20=20= =20=20=20(let=20((max=20(if=20(proper-list-p=20list)=0A+=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(+=202=20(length=20list))=0A= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(safe-length=20= list))))=0A+=20=20=20=20=20=20=20=20(dolist=20(n=20(number-sequence=20-1=20= max))=0A+=20=20=20=20=20=20=20=20=20=20(ert-info=20((prin1-to-string=20= n)=20:prefix=20"n:=20")=0A+=20=20=20=20=20=20=20=20=20=20=20=20(let*=20= ((l=20(copy-tree=20list))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20(ref=20(fns-tests--take-ref=20n=20l)))=0A+=20=20=20=20=20=20=20= =20=20=20=20=20=20=20(should=20(equal=20(take=20n=20l)=20ref))=0A+=20=20=20= =20=20=20=20=20=20=20=20=20=20=20(should=20(equal=20l=20list))=0A+=20=20=20= =20=20=20=20=20=20=20=20=20=20=20(should=20(equal=20(ntake=20n=20l)=20= ref))))))))=0A+=0A+=20=20;;=20Circular=20list.=0A+=20=20(let=20((list=20= (list=20'a=20'b=20'c)))=0A+=20=20=20=20(setcdr=20(nthcdr=202=20list)=20= (cdr=20list))=20;=20list=20now=20(a=20b=20c=20b=20c=20b=20c=20...)=0A+=20= =20=20=20(should=20(equal=20(take=200=20list)=20nil))=0A+=20=20=20=20= (should=20(equal=20(take=201=20list)=20'(a)))=0A+=20=20=20=20(should=20= (equal=20(take=202=20list)=20'(a=20b)))=0A+=20=20=20=20(should=20(equal=20= (take=203=20list)=20'(a=20b=20c)))=0A+=20=20=20=20(should=20(equal=20= (take=204=20list)=20'(a=20b=20c=20b)))=0A+=20=20=20=20(should=20(equal=20= (take=205=20list)=20'(a=20b=20c=20b=20c)))=0A+=20=20=20=20(should=20= (equal=20(take=2010=20list)=20'(a=20b=20c=20b=20c=20b=20c=20b=20c=20b)))=0A= +=0A+=20=20=20=20(should=20(equal=20(ntake=2010=20list)=20'(a=20b)))))=0A= +=0A=20;;;=20fns-tests.el=20ends=20here=0A--=20=0A2.32.0=20(Apple=20= Git-132)=0A=0A= --Apple-Mail=_BAD05BFC-3342-44F7-B1B3-1EF99C9E8C74-- From debbugs-submit-bounces@debbugs.gnu.org Sun Jul 17 12:00:28 2022 Received: (at 56521) by debbugs.gnu.org; 17 Jul 2022 16:00:29 +0000 Received: from localhost ([127.0.0.1]:48397 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oD6h2-0007iA-Hw for submit@debbugs.gnu.org; Sun, 17 Jul 2022 12:00:28 -0400 Received: from mail202c50.megamailservers.eu ([91.136.10.212]:47832 helo=mail193c50.megamailservers.eu) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oD6gy-0007ht-ET for 56521@debbugs.gnu.org; Sun, 17 Jul 2022 12:00:27 -0400 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1658073621; bh=O8p9O3UetEHKXcv7BBwZgBibyzMsk6RUxkgAiXskYRY=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=aG2RNxEwZTk5MDGMz5cOArTpPW1KgXcSnrSFz1mvBCf/QEP/YCn+qS4/IBs63SKnJ kHHCZqJpsVNBdM155pBPwi7oRHuktuJZZ+QlqZiTDH+TW6pwY9v9uuGhZ3E6IH2MG4 wehxKpmFCzDNLMyaPMm3qmbOWmdp10ZAWTiqfsiI= Feedback-ID: mattiase@acm.or Received: from smtpclient.apple (c188-150-171-71.bredband.tele2.se [188.150.171.71]) (authenticated bits=0) by mail193c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id 26HG0Hox085427; Sun, 17 Jul 2022 16:00:19 +0000 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Subject: Re: bug#56521: Add 'take' list operation [PATCH] From: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= In-Reply-To: <71564742-E071-4ABD-B8FF-FD8CCD6079B5@acm.org> Date: Sun, 17 Jul 2022 18:00:17 +0200 Content-Transfer-Encoding: quoted-printable Message-Id: <5B962C97-8E34-46C2-B794-D7CA022E6F64@acm.org> References: <3D32AB50-DC48-4AAE-831C-DDAC6225DFCF@acm.org> <878royueq7.fsf@gnus.org> <71564742-E071-4ABD-B8FF-FD8CCD6079B5@acm.org> To: Lars Ingebrigtsen X-Mailer: Apple Mail (2.3654.120.0.1.13) X-CTCH-RefID: str=0001.0A782F27.62D43215.005F, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-CTCH-VOD: Unknown X-CTCH-Spam: Unknown X-CTCH-Score: 0.000 X-CTCH-Rules: X-CTCH-Flags: 0 X-CTCH-ScoreCust: 0.000 X-Origin-Country: SE X-Spam-Score: 1.4 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Not much argument here; pushed to master. A couple of notes: I went for the C implementation of `ntake` because I already had the code, and because an elisp implementation would be slower than `take` for short lists or small N, and there very point of `ntake` i [...] Content analysis details: (1.4 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 1.0 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) -0.0 T_SCC_BODY_TEXT_LINE No description available. 0.4 KHOP_HELO_FCRDNS Relay HELO differs from its IP's reverse DNS X-Debbugs-Envelope-To: 56521 Cc: 56521@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) Not much argument here; pushed to master. A couple of notes: I went for the C implementation of `ntake` because I already had the = code, and because an elisp implementation would be slower than `take` = for short lists or small N, and there very point of `ntake` is speed. `nthcdr` has some elaborate code for handling bignum arguments which = makes some kind of sense since it's defined as an iteration of `cdr`. = Currently, `take` and `ntake` require fixnums because bignums didn't = seem to be worth the trouble. Before closing the bug, I'll make the new code pay their way by adding = some calls. `seq-take` is first in line for a makeover. From debbugs-submit-bounces@debbugs.gnu.org Mon Jul 18 08:51:09 2022 Received: (at 56521-done) by debbugs.gnu.org; 18 Jul 2022 12:51:09 +0000 Received: from localhost ([127.0.0.1]:49476 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oDQDM-00049p-OO for submit@debbugs.gnu.org; Mon, 18 Jul 2022 08:51:09 -0400 Received: from mail1447c50.megamailservers.eu ([91.136.14.47]:51116 helo=mail265c50.megamailservers.eu) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oDQDH-00049F-82 for 56521-done@debbugs.gnu.org; Mon, 18 Jul 2022 08:51:07 -0400 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1658148656; bh=SaT5L9s46/HZR190pDbIqmxV+7mdV1zZu3I2pj/Vhfc=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=YWE7wlDF/Ofk0xJzcDEr3qo07Jfd7idq2RPOhNxSf85A/DnfN5Q7gK2T45J210nxb HMiozc5bdwaNnKIdyOKBzQtDeAC5JkKwHHkLBAA8fG4FbgBH6ZRdeRlq5ec7lCJk8N Ep+DNvttHYVcf5mo5V5Us0DU4PV046xn0Z3fdP9Y= Feedback-ID: mattiase@acm.or Received: from smtpclient.apple (c188-150-171-71.bredband.tele2.se [188.150.171.71]) (authenticated bits=0) by mail265c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id 26ICorUT092393; Mon, 18 Jul 2022 12:50:54 +0000 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Subject: Re: bug#56521: Add 'take' list operation [PATCH] From: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= In-Reply-To: <5B962C97-8E34-46C2-B794-D7CA022E6F64@acm.org> Date: Mon, 18 Jul 2022 14:50:52 +0200 Content-Transfer-Encoding: quoted-printable Message-Id: References: <3D32AB50-DC48-4AAE-831C-DDAC6225DFCF@acm.org> <878royueq7.fsf@gnus.org> <71564742-E071-4ABD-B8FF-FD8CCD6079B5@acm.org> <5B962C97-8E34-46C2-B794-D7CA022E6F64@acm.org> To: Lars Ingebrigtsen X-Mailer: Apple Mail (2.3654.120.0.1.13) X-CTCH-RefID: str=0001.0A782F21.62D55730.001D, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-CTCH-VOD: Unknown X-CTCH-Spam: Unknown X-CTCH-Score: 0.000 X-CTCH-Rules: X-CTCH-Flags: 0 X-CTCH-ScoreCust: 0.000 X-Origin-Country: SE X-Spam-Score: 1.4 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: > `seq-take` is first in line for a makeover. Done. Naturally there are many more instances of code implementing `take` and `ntake` in creative ways but those will have to wait. Content analysis details: (1.4 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 1.0 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) -0.0 T_SCC_BODY_TEXT_LINE No description available. 0.4 KHOP_HELO_FCRDNS Relay HELO differs from its IP's reverse DNS X-Debbugs-Envelope-To: 56521-done Cc: 56521-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) > `seq-take` is first in line for a makeover. Done. Naturally there are many more instances of code implementing = `take` and `ntake` in creative ways but those will have to wait. From unknown Tue Jun 17 01:28:22 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Tue, 16 Aug 2022 11:24:06 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator