From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.help Subject: Re: Keywords as function arguments for control flow Date: Fri, 29 Nov 2024 07:18:29 +0100 Message-ID: <87y1125zre.fsf@gnu.org> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20437"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.12.7; emacs 31.0.50 Cc: Heime To: Heime via Users list for the GNU Emacs text editor Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Nov 29 07:19:34 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 1tGuLl-0005D5-OT for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 29 Nov 2024 07:19:33 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tGuL9-00015l-AU; Fri, 29 Nov 2024 01:18:55 -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 1tGuL3-00015c-41 for help-gnu-emacs@gnu.org; Fri, 29 Nov 2024 01:18:49 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tGuL0-0000Cu-9o; Fri, 29 Nov 2024 01:18:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=5mWmr48FnnwnHpZtZY3KGY+X14M6wa0zZG/BFR1YyUc=; b=cFw0eg97x1d4J0vh3MKp 8g5jG7REEE9dUd1mLklWvSrW3OmYg911bJV+Q3wmP5xaLDblRuioMTm30G9iZEhUvgy6yPF7Elg9I xtlSaI/ECe9N5hb/jsQ1yg/Yu6ElKdOjuZb4sNF1N5S/EZldQP4kqameF/ibkWl73WJVW3h7Kdts2 9Z7JMZ3YUUlwSXFKwjXep/0MukvERz6GvOwW3LFEd7oBtj5St84xVCO+s7ychdjVCzMIUXZJ72yTh Jn5Oiib+6Z1Yojr4j5r4ar+jEq3ENC9MdU6BAotjLOd0KCbtOomNl39Nop0LcxY+e0CxWVDqBMDOh SsEWCEB1qL54gQ==; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrhedvgdeludcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpefhvfevufgjfhgffffkgggtsehttdertddtredtnecu hfhrohhmpefvrghsshhilhhoucfjohhrnhcuoehtshguhhesghhnuhdrohhrgheqnecugg ftrfgrthhtvghrnhepleduvdegfeduvdejkeefteelgeetgfevhefhueffueffgeehgfeu fefgvdffgedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homhepthhhohhrnhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqkeeijeef keejkeegqdeifeehvdelkedqthhsughhpeepghhnuhdrohhrghesfhgrshhtmhgrihhlrd hfmhdpnhgspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohep hhgvihhmvggsohhrghhirgesphhrohhtohhnmhgrihhlrdgtohhmpdhrtghpthhtohephh gvlhhpqdhgnhhuqdgvmhgrtghssehgnhhurdhorhhg X-ME-Proxy: Feedback-ID: ib2b94485:Fastmail In-Reply-To: (Heime via Users list for the's message of "Thu, 28 Nov 2024 15:21:27 +0000") 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:148435 Archived-At: Heime via Users list for the GNU Emacs text editor writes: > How cam one use function arguments that use keywords for > applying control operations with pcase or cond? > > Consider this as example > > (defun cuprat (seqr) > > (if (eq seqr 'global) > (global-whitespace-mode 1) > (whitespace-mode 1)) ) > > (cuprat 'global) Your example uses symbols not keywords. Here are three versions which just return the keywords :global / :not-global instead of activating a mode just for better experimentation. You can replace :global and :not-global with (global-whitespace-mode 1) and (whitespace-mode 1) to get your actual function. --8<---------------cut here---------------start------------->8--- (defun cuprat (seqr) (cl-case seqr (global :global) ;; Fallback case with `otherwise' or `t'. (otherwise :not-global))) (cuprat 'global) ;;=> :global (cuprat nil) ;;=> :not-global (cuprat 'foobar) ;;=> :not-global (defun cuprat2 (seqr) (pcase seqr ('global :global) (t :not-global))) (cuprat2 'global) ;;=> :global (cuprat2 nil) ;;=> :not-global (cuprat2 'foobar) ;;=> :not-global (defun cuprat3 (seqr) (cond ((eq seqr 'global) :global) (t :not-global))) (cuprat3 'global) ;;=> :global (cuprat3 nil) ;;=> :not-global (cuprat3 'foobar) ;;=> :not-global --8<---------------cut here---------------end--------------->8--- You can easily go from symbols (global) to keywords (:global) just by replacing global with :global in which case you can also drop all quoting, i.e., 'global becomes just :global. Bye, Tassilo