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

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

RE: [External] : insert string at point with emacs-version


From: Drew Adams
Subject: RE: [External] : insert string at point with emacs-version
Date: Tue, 1 Feb 2022 19:44:27 +0000

> > `C-h f if'` C-h f cond'
> > `C-h i', choose Elisp manual,` g Conditionals'
> 
> Would the use of cond in the case below make sense?
> 
>   (let* ( (colors annotation-chroma)
>           (levels
>          (cond (>= emacs-version 28.0)
>                (alist-get (frame--current-backround-mode nil) colors)) ))

Pay attention to what `C-h f cond' tells you.

(cond ((>= emacs-version 28.0)
       (alist-get (frame--current-backround-mode nil) colors))

Typically you use `cond' with more than one
condition branch, and often with more than two.

The above code is the same as this:

(when (>= emacs-version 28.0)
  (alist-get (frame--current-backround-mode nil) colors))

or this:

(if (>= emacs-version 28.0)
    (alist-get (frame--current-backround-mode nil) colors))

Again, the Elisp manual, node Conditionals, tells
you these things.  Ask Emacs.

https://www.gnu.org/software/emacs/manual/html_node/elisp/Conditionals.html

Many people use `if' only with two branches, or
when the result matters.  Using `when' or `unless'
when the result isn't important makes that clear
to human readers.

When the result matters, you also have `and' and
`or', in addition to `if' and `cond'.

And know about `progn', to group multiple actions.


reply via email to

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