From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?B?Sm/Do28gVMOhdm9yYQ==?= Newsgroups: gmane.emacs.devel Subject: Re: What's missing in ELisp that makes people want to use cl-lib? Date: Wed, 15 Nov 2023 12:14:43 +0000 Message-ID: References: <87cywhsrcf.fsf@yahoo.com> <87cywgx1z0.fsf@web.de> <83wmuowwp3.fsf@gnu.org> <8334xcwank.fsf@gnu.org> <320999cc-6c83-2315-0044-cc0403400af3@gutov.dev> <9ab5d2bd-a648-cae0-a4a7-ae86be10af0f@gutov.dev> <87r0kuqxbf.fsf@gmail.com> <54e115a2-fc36-3056-a030-0dbf32416ddb@gutov.dev> <43f290b0-4119-597b-c89a-0fb4c7db1665@gutov.dev> <1e7fe1ef-af7d-3222-7b9e-b569b3c97ccf@gutov.dev> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37373"; mail-complaints-to="usenet@ciao.gmane.io" Cc: =?UTF-8?Q?Gerd_M=C3=B6llmann?= , Eli Zaretskii , michael_heerdegen@web.de, emacs-devel@gnu.org To: Dmitry Gutov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Nov 15 13:16:01 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1r3EoL-0009Xa-4a for ged-emacs-devel@m.gmane-mx.org; Wed, 15 Nov 2023 13:16:01 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3EnU-0005PC-K1; Wed, 15 Nov 2023 07:15:09 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3EnR-0005Oq-Bt for emacs-devel@gnu.org; Wed, 15 Nov 2023 07:15:05 -0500 Original-Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r3EnM-00057y-15; Wed, 15 Nov 2023 07:15:02 -0500 Original-Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-5094cb3a036so9422824e87.2; Wed, 15 Nov 2023 04:14:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700050497; x=1700655297; darn=gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=+lKeNJNCNsOj+UtN+PznyPDZJ7NrtnK+I/LF2rUZgZc=; b=X24VzpqR8rJf6hFme6ukdzFopb4wS+sKGkvYELU4ZTHfSE63jwdSaUird9hMeiKMn0 JAp3Cy5fz31UOuXI/CocBanslWjreMdf4O8pxcTXS6tUvyu5ps+baq7pt2oxNXrexY2d oTLPvL4cDs6FPrIK4SMJHYU2GXx8rvQUynpTb4/DTuy1LD0T+1zjJQ3aiPAT2qGOAh3V yoigyt3W4XPEtC7vmZmnlAWgazXVNdUf6kxJh1pQ46GYUdCzS0xtGR1Gf7zcKoWlQrlE NcExFCijDb3Xg/eLaOpSqZVXhPkW4tVigIdZIFDsBTFa/+hIfvcwbKRj5t5GI9jMacDv yQAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700050497; x=1700655297; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+lKeNJNCNsOj+UtN+PznyPDZJ7NrtnK+I/LF2rUZgZc=; b=lRHzlyl2cGcFs53BR5VyM0e+z4bvvKKzLjeIQjvAn2fEaWDQvFfbhXPQh8tMqwCMBy 70udx1nYhmgDYAlVWz2z+5WydS+zKNVxwRkQELCVV2+t/o5k7p39UFmLQStv6y0A5V8P LiH7B0GgK1b2wjm17lT/uWMp5KnYVTGDYIFM0gy5xPq5uD+A05Zy130/yVbY8KhnWKPG AN5yHVlHJdm1NwxK1AiBK4JVfRmcNo0wWZzhrChSSQQgwNnTPG1GKqYioUvYd2lO8ab3 OYWTRYhEs5qQDQmMUNQa58tHT86jXgwhB7QvEZR3q2XSIZ7LwgPX8MwkyKj0PnMZSXwE TfyA== X-Gm-Message-State: AOJu0YxKCMHDGE8GdGFeCEHqDvUbskegvMbACsa/y3MxtcKJdEU/0IGA YU4AtkVvAc3/hRlq+S6JgS5TT2QwdczAcDjJWBk= X-Google-Smtp-Source: AGHT+IHVTVnGhpp4QCe1Lutm29L35xkFjlAZOtnYuNMgd1cln0T352ZgZVjsdi7dC/BOvUj6ZLbfA66Y32s/gu3gKsU= X-Received: by 2002:a05:6512:23a9:b0:507:9e6c:e165 with SMTP id c41-20020a05651223a900b005079e6ce165mr10737566lfv.50.1700050496318; Wed, 15 Nov 2023 04:14:56 -0800 (PST) In-Reply-To: <1e7fe1ef-af7d-3222-7b9e-b569b3c97ccf@gutov.dev> Received-SPF: pass client-ip=2a00:1450:4864:20::12e; envelope-from=joaotavora@gmail.com; helo=mail-lf1-x12e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:312757 Archived-At: [replying to both subthreads here] On Wed, Nov 15, 2023 at 1:28=E2=80=AFAM Dmitry Gutov wro= te: > > But say I did that seq-do, then what is the seq-contains-p generic good > > for then? Why some many redundant generics that the user learns the > > hard way have to be consistent with each other? > So any new type gets a lot of functions implemented very easily, and > could add specialized implementations for performance. Fair enough. Except, as you noted, those optimizations can be completely nullified overnight, when trying to optimize something else. > the switchover would tank the performance of its callers. > As long as the observable behavior stays the same (aside from > performance), that seems fine. I don't think this is "fine" at all to tank user code performance, not from any library, much less such a basic foundation library. > > (seq-difference '(:m6-sparse 1 2 :double-o-seven 4) '(7)) ;; =3D> (1 2 = 0 0 4) > Very clever. I'm not thinking too well this time of night, but the first > part of the reply in this email probably answers the question (there is > a certain set of generics that must be implemeneted). Alright, if you must have them, they're all very trivial and I don't think it'll add much to your analysis. Here's the full compressed/sparse/lazy list impl: (cl-defmethod seq-do (function (l (head :m6-sparse))) (mapc (lambda (e) (if (eq e :double-o-seven) (mapc function '(0 0 7)) (funcall function e))) (cdr l))) (cl-defmethod seq-reverse ((l (head :m6-sparse))) (let (res) (seq-do (lambda (e) (push e res)) l) res)) (cl-defmethod seq-elt ((l (head :m6-sparse)) n) (elt (nreverse (seq-reverse l)) n)) (cl-defmethod seq-length ((l (head :m6-sparse))) (length (nreverse (seq-reverse l)))) (cl-defmethod seqp ((_l (head :m6-sparse))) t) (cl-defmethod seq-into-sequence ((l (head :m6-sparse))) (nreverse (seq-reverse l))) (cl-defmethod seq-subseq ((l (head :m6-sparse)) start &optional end) (cl-subseq (nreverse (seq-reverse l)) start end)) (cl-defmethod seq-copy ((l (head :m6-sparse))) (nreverse (seq-reverse l))) (cl-defmethod seq-into ((l (head :m6-sparse)) type) (cl-call-next-method (nreverse (seq-reverse l)) type)) (defvar my-compressed-list '(:m6-sparse 1 2 :double-o-seven 4 :double-o-seven 9 10 11)) (seq-difference my-compressed-list '(7)) ;; =3D> (1 2 0 0 4 0 0 9 10 11) (seq-elt my-compressed-list 0) ;; =3D> 1 (seq-elt my-compressed-list 4) ;; =3D> 7 (seq-elt my-compressed-list 5) ;; =3D> 4 (seq-elt my-compressed-list 10) ;; =3D> 10 (seq-elt my-compressed-list 1) ;; =3D> 2 (seq-elt my-compressed-list 3) ;; =3D> 0 (seq-elt my-compressed-list 13) ;; =3D> nil (seq-length my-compressed-list) ;; =3D> 12 (seqp my-compressed-list) ;; =3D> t (seq-subseq my-compressed-list 2 5) ;; =3D> (0 0 7) (seq-copy my-compressed-list) ;; =3D> (1 2 0 0 7 4 0 0 7 9 10 11= ) (seq-into my-compressed-list 'vector) ;; =3D> [1 2 0 0 7 4 0 0 7 9 10 11= ] (seq-into-sequence my-compressed-list) ;; =3D> (1 2 0 0 7 4 0 0 7 9 10 11= ) ;; non consing version (cl-defmethod seq-elt ((l (head :m6-sparse)) n) (cl-loop for e in (cdr l) for diff =3D (- n i) while (cl-plusp diff) sum (if (eq e :double-o-seven) 3 1) into i finally return (cond ((eq e :double-o-seven) 0) ((cl-minusp diff) (elt '(7 0 0) (- (1+ diff)))) ((zerop diff) e) (t nil)))) ;; non consing version (cl-defmethod seq-length ((l (head :m6-sparse))) (cl-loop for e in (cdr l) sum (if (eq e :double-o-seven) 3 1)))