[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Is there a way of setting a variable only when it exists?
From: |
Stefan Monnier |
Subject: |
Re: Is there a way of setting a variable only when it exists? |
Date: |
Mon, 14 Mar 2022 09:16:30 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) |
> I assume it would be fairly easy to code such a macro (using `boundp'),
> but maybe it exists already?
AFAIK it doesn't exist yet. The reason for it is that it is not
often useful. Typically there are two cases:
- If the var exist, you want to set it and if not you have no fallback.
In that case, it is typically harmless to set the var even when it
doesn't exist, so the code just uses `setq` without bothering to test
`boundp`.
- If the var exist you want to set it, and if it doesn't you want to do
something else. In that case, the something else tends to depend on
the specifics so (if (boundp 'foo) (setq foo ..) ...) is about s good
as it gets.
-- Stefan
- Is there a way of setting a variable only when it exists?, Marcin Borkowski, 2022/03/14
- Re: Is there a way of setting a variable only when it exists?, Eli Zaretskii, 2022/03/14
- Re: Is there a way of setting a variable only when it exists?,
Stefan Monnier <=
- Re: Is there a way of setting a variable only when it exists?, Emanuel Berg, 2022/03/14
- Re: Is there a way of setting a variable only when it exists?, tomas, 2022/03/15
- Re: Is there a way of setting a variable only when it exists?, Jean Louis, 2022/03/15
- Re: Is there a way of setting a variable only when it exists?, tomas, 2022/03/15
- Re: Is there a way of setting a variable only when it exists?, Jean Louis, 2022/03/15
- Re: Is there a way of setting a variable only when it exists?, tomas, 2022/03/15