Suppose one of the customizable variables in a package is var, and its default value is a list, list. I understand I can change the value of var to mylist using
(setq var mylist)
in my init.el.
Suppose though that I have a function fun and I want the value of var to be the result of applying fun to list. Can I simply do this?
(setq var (fun var))
I've done it and it seems to work as intended, but I want to make sure this is a good idea.
EDIT: My question was not very clear, so let me clarify the sort of thing I was worried about (this may be redundant in light of my comment to this answer by Drew. Suppose I add
(setq var (fun var))
to my init.el. How do I ensure that the default value of var has already been set when that line gets evaluated? Should I put this inside a with-eval-after-load? And how do I ensure that M-x load-file ~/.emacs.d/init.el won't result in var being set to the value of (fun (fun var))? Should I instead add the above line to something like emacs-startup-hook or after-init-hook?
I'm currently using a line in my init.el like the above for setting a variable to a value as a function of its default value. I'm relying on use-package, and in order to ensure that the default value of the variable had been set I had to put that line in the :config section of the relevant package, rather than in the :custom section (without setq). Also, the function I am currently using has the nice feature that (fun (fun var)) yields the same output as (fun var). So I have managed to get around both of my concerns.
Still, this seemed like an opportunity to try to understand how to do what I'm trying to do even if I'm not using use-package and if I have a function that's not idempotent.