[slime-devel] Intentionally dynamic variables in elisp?

Since variables in elisp are by default dynamically scoped, is there a coding convention for when you mean to take advantage of a variable being dynamic? Should one use *names* like in Common Lisp? -Peter -- Peter Seibel peter@gigamonkeys.com Lisp is the red pill. -- John Fraser, comp.lang.lisp

Peter Seibel <peter@gigamonkeys.com> writes:
Since variables in elisp are by default dynamically scoped, is there a coding convention for when you mean to take advantage of a variable being dynamic?
The convention that comes to mind is to only do this with variables that have been defvar'd and not just use it as a cheesy way to avoid passing parameters to subroutines.
Should one use *names* like in Common Lisp?
Definitely not :-)

Luke Gorrie <luke@synap.se> writes:
Peter Seibel <peter@gigamonkeys.com> writes:
Should one use *names* like in Common Lisp?
Definitely not :-)
Extra note: defvar'd variables in elisp are normally package qualified, e.g. starting with 'slime-', so they tend to be easy to distinguish from local variables without the *markers*.

Luke Gorrie <luke@synap.se> writes:
Peter Seibel <peter@gigamonkeys.com> writes:
Since variables in elisp are by default dynamically scoped, is there a coding convention for when you mean to take advantage of a variable being dynamic?
The convention that comes to mind is to only do this with variables that have been defvar'd and not just use it as a cheesy way to avoid passing parameters to subroutines.
Well, the situation is this: in slime (the function) I have a piece of information which eventually needs to get hung off the connection object. I can either add a parameter to a half-dozen functions between slime and the function that actually gets the connection object or I can bind a dynamic variable (which I'm happy to defvar). Which do you prefer? -Peter -- Peter Seibel peter@gigamonkeys.com Lisp is the red pill. -- John Fraser, comp.lang.lisp

Peter Seibel <peter@gigamonkeys.com> writes:
I can either add a parameter to a half-dozen functions between slime and the function that actually gets the connection object or I can bind a dynamic variable (which I'm happy to defvar). Which do you prefer?
The one you think is best. Elisp-wise either sounds fine and I know how twisty the startup code is.

Luke Gorrie <luke@synap.se> writes:
Should one use *names* like in Common Lisp?
Definitely not :-)
Indeed, * In some other systems there is a convention of choosing variable names that begin and end with `*'. We don't use that convention in Emacs Lisp, so please don't use it in your programs. (Emacs uses such names only for special-purpose buffers.) The users will find Emacs more coherent if all libraries use the same conventions. (info "(elisp)Coding Conventions") -- Johan Bockgård
participants (3)
-
bojohan+news@dd.chalmers.se
-
Luke Gorrie
-
Peter Seibel