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

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

Re: [External] : Re: Appending lists


From: Emanuel Berg
Subject: Re: [External] : Re: Appending lists
Date: Mon, 21 Jun 2021 01:04:12 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Stefan Monnier via Users list for the GNU Emacs text editor wrote:

>> might as well be
>>
>>   (nconc (list
>>           '("\\.bal\\'"     . balance-mode)
>>           '("\\.grm\\'"     . sml-mode)
>>           '("\\.lu\\'"      . lua-mode)
>>           '("\\.nqp\\'"     . perl-mode)
>>           '("\\.php\\'"     . html-mode)
>>           '("\\.pic\\'"     . nroff-mode)
>>           '("\\.pl\\'"      . prolog-mode)
>>           '("\\.sed\\'"     . conf-mode)
>>           '("\\.service\\'" . conf-mode)
>>           '("\\.tex\\'"     . latex-mode)
>>           '("\\.xr\\'"      . conf-xdefaults-mode)
>>           '("*"             . text-mode) )
>>          auto-mode-alist)
>
> Here `nconc` is a safe replace for `append` because indeed
> the first arg is a list you just constructed by `list` so
> you know for sure it's not shared with anything else.

Right.

> But the second above code is just an expensive no-op because
> your `nconc` will modify its first argument and not its
> second

Right!

> Here's another way you could write the code:
>
>     (setq auto-mode-alist 
>           `(("\\.bal\\'"     . balance-mode)
>             ("\\.grm\\'"     . sml-mode)
>             ("\\.lu\\'"      . lua-mode)
>             ("\\.nqp\\'"     . perl-mode)
>             ("\\.php\\'"     . html-mode)
>             ("\\.pic\\'"     . nroff-mode)
>             ("\\.pl\\'"      . prolog-mode)
>             ("\\.sed\\'"     . conf-mode)
>             ("\\.service\\'" . conf-mode)
>             ("\\.tex\\'"     . latex-mode)
>             ("\\.xr\\'"      . conf-xdefaults-mode)
>             ("*"             . text-mode)
>             ,@auto-mode-alist))

Hm, isn't that the coolest one by far?

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

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