From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Thibaut Verron Newsgroups: gmane.emacs.help Subject: Re: Checking conditions unrelated to expression Date: Sun, 8 Dec 2024 13:31:01 +0100 Message-ID: References: Reply-To: thibaut.verron@gmail.com 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="40542"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Heime via Users list for the GNU Emacs text editor To: Heime Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun Dec 08 13:31:55 2024 Return-path: Envelope-to: geh-help-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 1tKGS3-000AOz-2e for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 08 Dec 2024 13:31:55 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tKGRV-0001ev-IH; Sun, 08 Dec 2024 07:31:21 -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 1tKGRT-0001ec-6p for help-gnu-emacs@gnu.org; Sun, 08 Dec 2024 07:31:19 -0500 Original-Received: from mail-ot1-x334.google.com ([2607:f8b0:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tKGRP-0007dx-TK for help-gnu-emacs@gnu.org; Sun, 08 Dec 2024 07:31:17 -0500 Original-Received: by mail-ot1-x334.google.com with SMTP id 46e09a7af769-71ddca0b145so125872a34.2 for ; Sun, 08 Dec 2024 04:31:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733661074; x=1734265874; darn=gnu.org; h=cc:to:subject:message-id:date:from:reply-to:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ASLO2tU93akm4+kouMeiBccK5iQcsg+3z+EkAB+4EXU=; b=knlng3jTcm+UVjX03PvHflg/PzTplGuy+o56qkKi1508tkRqdTcLcQ/n2xPpmls+aE RAp5iXBRqAZh+V6yzZZS4DquFq6apxtPjizgJ4pm8VEPCsr10qxHp7FLzDl40grSRWwM 6094iyuvh8fzf0QHIM7A1yMlebm3LWBLME+yQOyqrkCH8kczMUorfeyDNolWZEi4xPz3 IlKEW7t+PbRkN6TEg+ybrAjBmFgr8Czj0d+cutbXmYF4FdDaUuyStwofFD/7fd3rqyXj N3R68/pdJxiMPBR1AS+bqRUzG2YD98L9h1guDCJZDVAz3vX+LOF99Cxv1Kfsvc/XS6Fv fFpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733661074; x=1734265874; h=cc:to:subject:message-id:date:from:reply-to:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ASLO2tU93akm4+kouMeiBccK5iQcsg+3z+EkAB+4EXU=; b=XPs3jSNwnQdydmPO0B+l9lJZp0otAL7jI6ghASkb2yaxEseFKPI/Hw4xKXV6VjNbXP T4iWBT+Rpl0FTGUGC1Pldy3OOrtGkTpUh1/bkmv0VW8EjK801/4+VdZ+YOr1jEVysjIQ FT9vZSVWSBAhbky+1YNCDPAma27VqvuqVzaGaXKnBuLH6UhErWc6SU6oneZiosgc0xx1 WkeBmcLCNPvpCX5WjUf0HCtILBzfo33EYxeQbdhkq7rPS9B33qpwegyG/Gfqw4rA9u81 630zS/ZE+2oGQ7Q/NYWv0BPsTvCZIC9GccWtjD2/HMh/uC0Z5Q7LG7OtQCzhcMtiFqQn TVHg== X-Gm-Message-State: AOJu0Yy08vEp6pIjULAM1gwmj8WXmtsb3LPr1Cgamo/8qYX1MUx3f3V4 tJe3A605+NRWwbF2nrYFYfA3RKmFBZRI/skbyUkd0y+CO8UarMiLoaPS4IU+2P+DpnaqqSOgXXN v8oI1tS9T5xYo33GnQ5g3hgXuN8E= X-Gm-Gg: ASbGnctiA6uVVtf4uYwHILGVpwZtG77hHfDFaow2PDmfE/Zl9/TYamnu6TwNvTq90pB i2FHUwoHUFqHinv2hE13XooNC/YnjD3o= X-Google-Smtp-Source: AGHT+IE2sSkktm38/sFsdcA/oBMNtwz/4E+2BGmk9S8n1au1iUXUgezRMWjB3Vc7GJgFkAYgXOQ14HlIzVm8f3bm1e8= X-Received: by 2002:a05:6871:c709:b0:29e:79ce:933a with SMTP id 586e51a60fabf-29f73a5649emr2019870fac.12.1733661073874; Sun, 08 Dec 2024 04:31:13 -0800 (PST) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::334; envelope-from=thibaut.verron@gmail.com; helo=mail-ot1-x334.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, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:148676 Archived-At: Le dim. 8 d=C3=A9c. 2024 =C3=A0 13:06, Heime via Users list for the GNU Ema= cs text editor a =C3=A9crit : > It looks like pcase can only be used with some variable condition > > This will check condition of featr > > (pcase featr > ('this (do-this)) > ('that (do-that)) > (_ (message "some message")) > > What if I want to check a number of conditions, not all dependent upon > featr, what should one do? > > Suppose I want to test (eq duck 'quack), cannot use a pcase because tests > are dependent upon featr. > > (pcase featr > ('this (do-this)) > ('that (do-that)) > (_ (message "some message")) > You can use a plain case-switch, rather than a pattern-matching one: (cond ((eq featr 'this) (do-this)) ((eq featr 'that) (do-that)) ((eq duck 'quack) (do-duck)) (t (message "blabla"))) https://www.gnu.org/s/emacs/manual/html_node/elisp/Conditionals.html You can also replace the first two cases by a pattern-matching case, if you'd like: (cond (pcase featr ('this (do-this) t) ;; important to return non-nil in each branch ('that (do-that) t) (_ nil)) ((eq duck 'quack) (do-duck)) (t (message "blabla")))