help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Keywords as function arguments for control flow


From: Heime
Subject: Re: Keywords as function arguments for control flow
Date: Sat, 30 Nov 2024 11:55:47 +0000





Sent with Proton Mail secure email.

On Saturday, November 30th, 2024 at 11:47 PM, Jean Louis <bugs@gnu.support> 
wrote:

> (defun cuprat (seqr)
> (pcase seqr
> ('global (global-whitespace-mode 1)) ;; if seqr is 'global
> (_ (whitespace-mode 1)))) ;; default case for other values
> 
> (cuprat 'global)
> (cuprat 'other)
> 
> 
> Explanation
> 
> pcase matches the argument seqr to specific patterns (like 'global).
> 
> If seqr is 'global, it applies (global-whitespace-mode 1).
> 
> The underscore (_) is a catch-all pattern that matches anything else, so in 
> that case, (whitespace-mode 1) is called.
> 
> 
> (defun cuprat (seqr)
> (cond
> ((eq seqr 'global) (global-whitespace-mode 1)) ;; if seqr is 'global
> (t (whitespace-mode 1)))) ;; default case for other values
> 
> (cuprat 'global)
> (cuprat 'other)
> 
> 
> Explanation
> 
> The cond form evaluates each condition in order.
> 
> The first condition checks if seqr is 'global, and if so, it runs 
> (global-whitespace-mode 1).
> 
> The (t ...) clause is a fallback that handles all other cases, applying 
> (whitespace-mode 1).
> 
> 
> Personally I have not ever used pcase - Jean

I have used both.  The question is about how to pass keywords 
(i.e. with :something) as function arguments. 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]