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: Instead of pcase Date: Fri, 1 Dec 2023 10:02:37 +0000 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> <83fs0navpj.fsf@gnu.org> <838r6ebfhw.fsf@gnu.org> 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="28736"; mail-complaints-to="usenet@ciao.gmane.io" Cc: owinebar@gmail.com, rms@gnu.org, dmitry@gutov.dev, philipk@posteo.net, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Dec 01 11:00:42 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 1r90KA-0007ER-4a for ged-emacs-devel@m.gmane-mx.org; Fri, 01 Dec 2023 11:00:42 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r90JG-000537-7Z; Fri, 01 Dec 2023 04:59:46 -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 1r90JE-00052z-O5 for emacs-devel@gnu.org; Fri, 01 Dec 2023 04:59:44 -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 1r90JC-0003oy-Um; Fri, 01 Dec 2023 04:59:44 -0500 Original-Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-50bbfad8758so2628012e87.3; Fri, 01 Dec 2023 01:59:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701424779; x=1702029579; 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=HMSMCwKXet1SrG7SLQV22W/WUbRGy9HLKJEcWsD5vPE=; b=YWXUiIeCvBJ16IjIFZtPI5ghsNrijZCnZeWAbowcFZh6w7kxAXnfattT38yHnnpmFl zYYg9XTkUm7+552qtx5fPzez5r1vsllSTYM7IMzRhzTjBs+YYE8PIBALxPe4kdXqde05 WCRCQwy4cXBGcslN78welkutHf8GQzQQrQbjGob834sdIA5l1DV5SkKBU6x8tp/uu0kQ +uUrTnWoBqsC2oAQmV254abE3KOg9kcAvkUDKOvAD4oy6IIe4fh3criFvSaLup8ByWb6 qQlbBiX1rV1grHimc89OfuWROGjUNREsT2oc8CMmIt//ALnbmGZj5ECSQD1ZgnJW9lGP HVAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701424779; x=1702029579; 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=HMSMCwKXet1SrG7SLQV22W/WUbRGy9HLKJEcWsD5vPE=; b=vyEnkuJV8We5ZkW2Opg7tOSUU12vIbhMizJrk7BaR8TbknCG1F0jznnuYGwiznSh2G CapNaIVPrHVX6+Ze1usK6QAaYxvgJuY0hT8zA1//ik3H72E7FxuRT4HlLw590/sH1aOT CJiRGwyMq/1vIrTPXYDAspXiP8uJNRfUCAP2j1oMYgaTlCLcPyhETf52uqGPcITbdy4V /mbZSsuB0iP7l8Pc+p0jcrqNcY43LE33r82Re2FsEL0qjQ3Cug54xKaOAsvCfr5v4iCs 98PNLDsLXNkRrDml5d25rMKjaAuLfOl4pXLuOwbH7zGBhI7nF3y8AcG0QkGTFZusYpyO UpsQ== X-Gm-Message-State: AOJu0YxIBbbPxlQ9RWB1V6zHsEeVss+Bssb8MIwwjEUw7aTXvfLsAXZW JDG0R0HL3FT5pwoysI/+xOckHAPi6mhScSrP5rFPWjnM X-Google-Smtp-Source: AGHT+IFl+7UsRJeSsNxdf/FuD9h/vUL+Ntua28atPi0/o6DfzpOyVl3lvBHcExpWC8rsxXZIa7Y0XdvmVhg77FNPMNc= X-Received: by 2002:a05:6512:10c8:b0:50b:d944:c055 with SMTP id k8-20020a05651210c800b0050bd944c055mr362304lfg.279.1701424778746; Fri, 01 Dec 2023 01:59:38 -0800 (PST) In-Reply-To: <838r6ebfhw.fsf@gnu.org> 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:313430 Archived-At: On Fri, Dec 1, 2023 at 6:31=E2=80=AFAM Eli Zaretskii wrote: > The validity is not the point I wanted to make. The point I wanted to > make is that the accepted syntax includes unusual uses of the period > and other punctuation, some of which have special meaning. And that > makes the code harder to read and understand. > > Incidentally, the actual code from which this were taken is > > (`(,hookfun . (,start ,end ,collection . ,plist)) > > Which has _two_ periods, not one, which are AFAIU redundant, as far as > the Lisp reader is concerned. They are NOT redundant. Meaning you can't simply take them out and have the expression mean the same: that's what "redundant" means to me, at least. But like so often in programming, there are different ways to say the same. In pcase as in normal list-making life, the above form is the same as. (`(,hookfun ,start ,end ,collection . plist)) So while it's reasonable to take issue with the author's choice of one of many equivalent list-representing constructs, I don't think one should blame their choice of 'pcase' here. Personally, I don't really fault the author too much in this case: if the thing to be destructured were an entry of an alist, I actually like to see things represented in the original alternative. As you probably know, one as a maintainer often has to work with data structures that one didn't invent and wishes weren't like they are. Very often these structures are contorted, incrementally evolving lists where certain positional elements mean certain things for the structure. One may be completely innocent of inventing this spaghetti and yet one has to work with it. This happens very frequently in Emacs, it certainly happens to me. > > IMO what's relatively contrived in pcase-- but very well contrived > > I should add -- is the use of the backtick and comma, whose > > usual job is output and list construction, to do the reverse, > > to express input and list destructure. > > Again, the point is not that the construct cannot be explained away or > interpreted correctly given enough time and consulting the docs. First, I'd like to say that when I first met pcase, I used to share your views and now I don't. It's not that I encounter pcase on constantly these days (I don't), it's just that I quickly changed my view once someone gave me a piece of insight about it. That insight has already surfaced here, but perhaps has not been underlined enough. So, in these emails, I'm trying to explain to you how to change your view of these pcase constructs in a constructive way, to help speed up your understanding of important parts of our code base. I hope this message gets across. If you've already decided you will never understand 'pcase' and will forever reach for the docs, that's a legitimate position, but it also means I can't be much help in this sub-discussion. It is _easy_ to explain that "scary" construct _if_ you learn to _lean_ on what should be probably existing knowledge. No doc-consulting necessary. You take a backtick-starting construct with as many scary periods things as you can find and then, say `(,foo . (,bar . ,baz)) And then ask yourself: "what kind of list does this build if I just let-bind foo, bar and baz to 42?". And then you answer yourself "Why, it's the improper list (42 42 . 42) made up of just two cons cells and 3 fixnums!". So _that's_ the kind of list that can be destructured with the pcase expression. This solves the reading problem. Now the writing problem. To author new pcase patterns one uses more or less the same process. One again leans on one's existing knowledge of how the list structure would be expressed with backtick-and-quote. So once you know the list structure in your mind you write it as a backtick-and-quote expression, just as if you were going to craft that list (though you aren't of course). Then once you're happy with your expression, you may take it and you put it in one of the BINDINGS left-hand part of a 'let'. Then you rename that 'let' to 'pcase-let' and away you go! HTH