hyperbole-users
[Top][All Lists]
Advanced

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

Re: how to run a elisp-function


From: Jean Louis
Subject: Re: how to run a elisp-function
Date: Tue, 11 May 2021 19:36:42 +0300
User-agent: Mutt/2.0.6 (2021-03-06)

* Robert Weiner <rsw@gnu.org> [2021-05-08 20:33]:
> You can use something like:
> 
> (push '("Name" . "https://url-with-%s-in-it";) hyperbole-web-search-alist)
> 
> or you could use a setq call and just replace the whole list with the items
> you want where you want them.

Robert this is not for you, it is just my mind exercise that can
help people understand it is better for alist to use alist
related functions. They are in the Manual at (info "(elisp)
Association Lists")

While `push' does work, single push would work, but is kind of
risky if person is trying to work with it. 

(setq my-alist '()) ⇒ nil

(push '("Name" . "https://www.example.com";) my-alist) 
  ⇒ (("Name" . "https://www.example.com";))

But repeated push will create duplicate:

(push '("Name" . "https://www.example.com";) my-alist) 
  ⇒ (("Name" . "https://www.example.com";) ("Name" . "https://www.example.com";))

(alist-get "Name" my-alist nil nil 'equal) ⇒ "https://www.example.com";

(setf (alist-get "Name" my-alist nil nil 'equal) 
"https://www.other-example.com";) ⇒ "https://www.other-example.com";

Now we have got duplicates because push was used to set the key
and not (setf (alist-get ...))

my-alist ⇒ (("Name" . "https://www.other-example.com";) ("Name" . 
"https://www.example.com";))

It will return the correct result though:

(alist-get "Name" my-alist nil nil 'equal) ⇒ "https://www.other-example.com";

What if user tries to make 3 times push with the sligthly
different key? Then it will end up with duplicates both in
variable description and in the init file.

I am not sure how the function in Hyperbole works, if it does not
call alist functions it could even start showing duplicates.


Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/
https://rms-support-letter.github.io/




reply via email to

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