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

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

Re: let-alist can't deal with the keys which includes spaces.


From: tomas
Subject: Re: let-alist can't deal with the keys which includes spaces.
Date: Tue, 20 Jul 2021 19:08:29 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

On Tue, Jul 20, 2021 at 06:52:41PM +0200, Emanuel Berg via Users list for the 
GNU Emacs text editor wrote:
> tomas wrote:
> 
> > yes, and `let-alist' expects symbols as keys.
> 
> Uhm, what is the purpose with `let-alist' and "dotted symbols"
> to begin with?

`let-alist' is just a handy way to destructure an alist.

Assume we have

  (setq colours '((poppy . red) (cornflower . blue) (sunflower . yellow)))

Instead of doing

  (let ((rose (alist-get 'rose colours))
        (cornflower (alist-get 'cornflower colours))
        (sunflower (alist-get 'sunflower colours)))
    ;; do something with rose, cornflower...
    )

you just do

  (let-alist colours
    ;; do something with .rose, .cornflower...
  )

which is kind of less repetitive. The dots are part of the symbol
name, they aren't special Lisp syntax. Probably they are there to
help avoiding collisions with your variable names. If you don't
name your variables `.foo', all will work out nicely.

Cheers
 - t

Attachment: signature.asc
Description: Digital signature


reply via email to

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