From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuri Khan Newsgroups: gmane.emacs.devel Subject: Re: Instead of pcase Date: Tue, 21 Nov 2023 12:34:51 +0700 Message-ID: References: <87fs169mjj.fsf@posteo.net> <093f11a1-57c2-5e56-d39b-26fef1c67cbb@gutov.dev> <25942.25061.217864.329049@retriever.mtv.corp.google.com> <87zfzdcz6z.fsf@posteo.net> <763f067b-4ca9-1eba-9f3c-424c38589e9c@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="31032"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Dmitry Gutov , philipk@posteo.net, emacs-devel@gnu.org To: rms@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Nov 21 06:36:00 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 1r5JQV-0007op-Md for ged-emacs-devel@m.gmane-mx.org; Tue, 21 Nov 2023 06:35:59 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5JPk-0004XT-7h; Tue, 21 Nov 2023 00:35:12 -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 1r5JPh-0004Tj-M7 for emacs-devel@gnu.org; Tue, 21 Nov 2023 00:35:09 -0500 Original-Received: from mail-vk1-xa36.google.com ([2607:f8b0:4864:20::a36]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r5JPf-0003EN-H8; Tue, 21 Nov 2023 00:35:09 -0500 Original-Received: by mail-vk1-xa36.google.com with SMTP id 71dfb90a1353d-4ac0d137835so1854073e0c.2; Mon, 20 Nov 2023 21:35:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700544903; x=1701149703; 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=iKpD7F8sYDW4JwgYFRrfrAwYaHSpYhwd+6bVs3fls5g=; b=EqF9D3W9Vx2FP+2NU4yCN71c2q+aMkri42XIVNB7fTlDnjph11VUh+yTom0APsnDiQ DrBCAwY617Ts9+5VLfO93+m4KYCUCTmKT0E2iAA68GlK68wXKVlFWwNLOc6M5F02fi46 1jBCzn2YzsXr76YUzxwnyWDSBEMfnp27R0SkVSkPciOozyppjuGjWLZWKDXodBzbti+D uOWfjMrMEa6Mr3Nmazg+q87AGcpJcfRrD/l8lmK6kIIW0FF6KFgU6cw7go6D17nsYpBO R6q0u13UqtMbtdLI7uMoEshf89ImjslAsMy42e5psgmkMmBvHPCo8T8/Q1Ofs4z+dff3 9amw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700544903; x=1701149703; 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=iKpD7F8sYDW4JwgYFRrfrAwYaHSpYhwd+6bVs3fls5g=; b=e1m/tIMKQFft0eNQFQksQF0zULR4KE9XN9I4JM8oTP54qsQLfpVunyHAFB1JZuW4VF DHyvtyClKE/aPeSg4lTrwS18IEzJae8ghgrm2R9MocixpdyQIzRPry9j0VS18VAI4yD8 /yKyk95c/OD/S+NUNOIUYlO6U0OoGOJsr4z1r81+DMODIWgcuby/JkCfadQnrTAgj7Wq LL3VUD+1232nj+rkjNp04eXdVhNEU2Ddal2jOky59J6Hy4zOZmxzQPfnE8rcW4PyOfv+ ZKox3nCguo/ODf7Be36JRhU1nSYNCBrRfX9C0H1wqU/rCvczzXuTrdtQNh6O7wKsbXPQ od8Q== X-Gm-Message-State: AOJu0YzYNEzSpu4sZZXsuG/0BGHP4Yzn31u4QrxiXQQnf0ojqUQq5thT QvGKXseoLBXwG+Xt1A3eyNGQR0TSEPnAbkctLfVtMQ2mmJo= X-Google-Smtp-Source: AGHT+IGup2ep7WQ39fFLtzB7r60ATVemSmM1YZyHtlDf0+zyIih22P2PtHVIKnA0pBoIXMG8aLA3EmwvZ0rJkdjUOoY= X-Received: by 2002:a1f:ec81:0:b0:495:febd:9187 with SMTP id k123-20020a1fec81000000b00495febd9187mr8964033vkh.0.1700544903472; Mon, 20 Nov 2023 21:35:03 -0800 (PST) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::a36; envelope-from=yurivkhan@gmail.com; helo=mail-vk1-xa36.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:313091 Archived-At: On Tue, 21 Nov 2023 at 09:42, Richard Stallman wrote: > > To interpret those backquotes and commas, one can imagine that the th= ey > > do the inverse of the usual. > > I uderstand that when you say it, but when I saw the line > > > > (`(,hookfun . (,start ,end ,collection . ,plist)) > > I was not sure which part of the line that rule applies to. > > In particular, what is the reason for the period and inner > parenthsses? Why doesn't the code say this? > > > > (`(,hookfun ,start ,end ,collection . ,plist) > > Would that be equiva;ent? I am looking at this part of code for the first time so let=E2=80=99s see w= hat I can make of it. The code in the revision I=E2=80=99m looking at looks like this: (defun completion-at-point () "=E2=80=A6" (interactive) (let ((res (run-hook-wrapped 'completion-at-point-functions #'completion--capf-wrapper 'all))) (pcase res (`(,_ . ,(and (pred functionp) f)) (funcall f)) (`(,hookfun . (,start ,end ,collection . ,plist)) =E2=80=A6) ;; Maybe completion already happened and the function returned t. (_ =E2=80=A6)))) First, this runs a hook and binds its returned value to the local name =E2= =80=98res=E2=80=99. Then it matches that value to one of three patterns, the last of which is a match-all. The first two look like they match =E2=80=98res=E2=80=99 to= a cons cell. I go to look a the documentation of =E2=80=98completion-at-point-functions=E2=80=99: should return either nil, meaning it is not applicable at point, or a function of no arguments to perform completion (discouraged), or a list of the form (START END COLLECTION . PROPS), where: Aha! The two latter formats are the same as the inner matchers in the first two pcase alternatives. I look at =E2=80=98completion--capf-wrapper= =E2=80=99 to see if it supplies the =E2=80=98car=E2=80=99 part. (defun completion--capf-wrapper (fun which) (if =E2=80=A6 (let ((res (funcall fun))) =E2=80=A6 (if res (cons fun res))))) It seems it does! So the pcase matchers in =E2=80=98completion-at-point=E2= =80=99 are written that way because the wrapper returns a cons cell with the function in car and its result in cdr, and one of the possible formats of the result is a sub-list. I=E2=80=99m pretty sure collapsing that `(,hookfun . (,start =E2=80=A6)) to= `(,hookfun ,start =E2=80=A6) would be an equivalent transformation, but I also feel it would mash together the expectations from the wrapper and the completion-at-point function thus increasing cognitive load for the reader. I further notice that, curiously, the inside of =E2=80=98completion--capf-wrapper=E2=80=99 analyses the result of (funcall = fun) with a cond, consp, listp, functionp, and nthcdr 3 to check some conditions, then extracts its car, nth 2, and nthcdr 3 to pass them to a nested =E2=80=98try-completion=E2=80=99 call, and it=E2=80=99s not trivial for me = to follow as I have to keep in mind the general structure of the list. If I were trying to grok that function, I would, for personal reference, try to rewrite it to pcase, binding the parts of the list to descriptive names.