From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Kangas Newsgroups: gmane.emacs.bugs Subject: bug#68029: 29.1; (elisp) `pcase Macro': misleading mention of `cl-case' Date: Mon, 25 Dec 2023 08:53:52 -0800 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24387"; mail-complaints-to="usenet@ciao.gmane.io" To: Drew Adams , 68029-done@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Dec 25 17:55:23 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1rHoEc-00065F-Uj for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 25 Dec 2023 17:55:22 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rHoEE-0003sG-Fk; Mon, 25 Dec 2023 11:54:58 -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 1rHoEC-0003rR-ME for bug-gnu-emacs@gnu.org; Mon, 25 Dec 2023 11:54:56 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rHoEC-0003LP-Ds for bug-gnu-emacs@gnu.org; Mon, 25 Dec 2023 11:54:56 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rHoEI-0004v6-IR for bug-gnu-emacs@gnu.org; Mon, 25 Dec 2023 11:55:02 -0500 Resent-From: Stefan Kangas Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Mon, 25 Dec 2023 16:55:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 68029 X-GNU-PR-Package: emacs Mail-Followup-To: 68029@debbugs.gnu.org, stefankangas@gmail.com, drew.adams@oracle.com Original-Received: via spool by 68029-done@debbugs.gnu.org id=D68029.170352324818840 (code D ref 68029); Mon, 25 Dec 2023 16:55:02 +0000 Original-Received: (at 68029-done) by debbugs.gnu.org; 25 Dec 2023 16:54:08 +0000 Original-Received: from localhost ([127.0.0.1]:55234 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rHoDQ-0004to-3V for submit@debbugs.gnu.org; Mon, 25 Dec 2023 11:54:08 -0500 Original-Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]:50229) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rHoDN-0004tK-PC for 68029-done@debbugs.gnu.org; Mon, 25 Dec 2023 11:54:06 -0500 Original-Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-554473c653aso3304419a12.0 for <68029-done@debbugs.gnu.org>; Mon, 25 Dec 2023 08:53:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703523233; x=1704128033; darn=debbugs.gnu.org; h=to:subject:message-id:date:mime-version:references:in-reply-to:from :from:to:cc:subject:date:message-id:reply-to; bh=gieQJRQaIYfxldYq9mehGNE9oU+TplzJI8JlNC4XD3Q=; b=CztnAD8Q/ifqfuzcBwQheQZbJhGbqX/cq6GhwQ9XV9elIpVY423fs7TMUv9sdXB1A3 OwfeVrMJNZc8XisyIbMPMLChE+5GvCGcp7A7HP7joKEIrAmn8TTffUgjGULq4DObdAfJ U2l6EC1xug/MPVItbM2+RszaKqjU+FdRxEjp1PpZOL6ofVX82iwLTxqp5h6CUUu4LANL fjSYkMSca6z4wDX+yDqnZ5GkjVMOu3B+p5YRDJ5WPwzQaIz0GR4x5QsOqScVuBtjIGBV N2GkPoIM5Rh1dsvYEhoA6lg5WDEWQhhpvmVIgf1KWmwJ4LM5R7F6xgCb9+n74aFIjr/a vVWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703523233; x=1704128033; h=to:subject:message-id:date:mime-version:references:in-reply-to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gieQJRQaIYfxldYq9mehGNE9oU+TplzJI8JlNC4XD3Q=; b=Ht0+dNprVJTADuvtfIZ0gr1WmwqJWBiu5Xqqp8TO9ykArVmuETbEytC11fd2bTR38w EuFwe21A44dpVFaYGN+Ns1vH9ECrfvo5qxLk7+y1VwaH8hnhMfxRhV/Pxz6F7wRl0qcd AdcEqnuTpfQjeAL2sG2ZjTqJEI8aULpxRbkGe5d9J3Oxp3vbdQQBYKyPBRhYzllvwdzd /ioYmlYmrPRq9LcqkNJZq9fLRX13MGUJ8grCSTS9EtkUKyFenTiF8Bck+uZ9lATv7KWL fbwtIuO6NnjNPLxkfIB0FVn+XrlKQC52DKu6FwMMClEZA8bujUQzfuUvNjKMfFp6wjUS iAyw== X-Gm-Message-State: AOJu0Yyp2DEx7eC72pgRN65SajDrnxqlVKKEVjLF4tRpamWkT2wpaSp1 1xr8DyJzQe+fS2Lut4vI+sy8z9d4hK/voWYnmL0= X-Google-Smtp-Source: AGHT+IFskVFvWmT6DIZZqEDXttEQyLg61zjZxHkrF1VtOeWXq0c5JPN/vmJwoGu75M5+vIz2ub/xI+Y8VlJs1CLTmoA= X-Received: by 2002:a50:d547:0:b0:555:1365:7871 with SMTP id f7-20020a50d547000000b0055513657871mr179657edj.41.1703523232946; Mon, 25 Dec 2023 08:53:52 -0800 (PST) Original-Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Mon, 25 Dec 2023 08:53:52 -0800 In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:276874 Archived-At: Drew Adams writes: > I find this comment misleading/incorrect: > > With 'cl-case', you would need to explicitly declare a local variable > 'code' to hold the return value of 'get-return-code'. Also 'cl-case' is > difficult to use with strings because it uses 'eql' for comparison. > > In fact, with `cl-case' the code is at least as simple: > > (let* ((val (get-return-code x))) > (if (stringp val) (message val) > (cl-case val > (success (message "Done!")) > (would-block (message "Sorry, can't do it now")) > (read-only (message "The shmliblick is read-only")) > (access-denied (message "You do not have the needed rights")) > (val (message "You do not have the needed rights"))))) > > Yes, it's true that comparison is with `eql', so for a string value you > need to test that separately (or intern and then test symbols with > `cl-case'). But there's no need to use any `code' variable. This shows that you do need to use a `code' variable (you named it `val' though), and that the pcase version is indeed better. > If you can't come up with a better example to show advantages of `pcase' > over `cl-case' (and that should be easy to do), then don't say anything > about `cl-case'. Or maybe just tell the truth: `cl-case' handles _one > simple `pcase' use case_ in a simpler way. IOW, if you're just testing > equality of the expression's value against particular symbols then > `cl-case' is simpler and clearer. No, the reality is that `pcase' has *many* advantages over `cl-case'. The example is just intended to showcase some of them. > Even clearer is just this (same for the `pcase' example): > > (message > (let* ((val (get-return-code x))) > (if (stringp val) val > (cl-case val > (success "Done!") > (would-block "Sorry, can't do it now") > (read-only "The shmliblick is read-only") > (access-denied "You do not have the needed rights") > (val "You do not have the needed rights"))))) I'm not sure that's indeed easier for a beginner ELisp developer to follow. So I don't think it's worth making that change. > (And you've presumably misspelled schmilblick ;-): > https://en.wikipedia.org/wiki/Schmilblick) I don't follow, sorry. So I'm closing this bug report.