[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: sending function arguments to recursive function calls
From: |
Dmitry Gutov |
Subject: |
Re: sending function arguments to recursive function calls |
Date: |
Mon, 20 May 2013 23:31:40 +0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (windows-nt) |
"Pascal J. Bourguignon" <pjb@informatimago.com> writes:
> Then you meant to write:
>
> bar
>
> not:
>
> baz
>
Right. Sorry.
>> It's ugly because this kind of code is hard to reason about and,
>> consequently, hard to modify. Suppose I want to rewrite `foo' (and
>> suppose it's longer than this one line).
>
> Yes. That's why you should adopt the CL convention of naming all the
> special variables (those with dynamic binding) with stars:
>
I agree it's a good convention in CL (and Clojure), but Elisp has its
own convention: name the variable starting with the package prefix.
Until we have real modularity, it should be good enough.
>> Can I rename `bar' to something else?
>
> Yes. You should name it *bar*, and declare it special locally. Right,
> for now (declare (special *bar*)) has no effect in emacs lisp since it's
> the default, but it states your intent!
Yes, I think, currently only byte-compiler looks at it, and warns the
user when it sees undeclared variables.
>> No idea: to be absolutely sure,
>> I have to search the definitions of all functions that `foo' calls,
>> and if I find a `bar' reference in any of them, I'll now have to
>> search for any other functions that call them, etc. IOW, this makes
>> for terrible composability.
>
> Definitely. That's why the default is lexical binding, and you have to
> declare specially variables with dynamic binding, either with declare
> special, or globally with defvar or defparameter.
>
>
>> The behavior is ugly because it allows the code to be written this way.
>>
>> A worse example is when `bar' is one of the arguments to `foo' (ugh).
>
> Global or local special declarations are still possible, even for
> parameters.
...in CL, right? Your earmuff example didn't work for me in Emacs with
lexical-binding t, `(declare (special *bar*))' doesn't replace the need
for `defvar'ing it.
I'm not sure how I feel about special local variables and parameters.
The problem with tracking down callers/callees graph applies to both of
these types, as far as I can tell, so each local variable of this kind
might as well be declared global.
During the few years I've been using Emacs, I think I've only used the
ability to change the value of a parameter in a caller function once,
deep inside the Helm codebase. Sure enough, in a few months, the caller
function code has changed, and my function broke.
- Re: sending function arguments to recursive function calls, (continued)
- Re: sending function arguments to recursive function calls, Gauthier Östervall, 2013/05/09
- Re: sending function arguments to recursive function calls, Stefan Monnier, 2013/05/09
- Re: sending function arguments to recursive function calls, Gauthier Östervall, 2013/05/12
- Re: sending function arguments to recursive function calls, Stefan Monnier, 2013/05/13
- Re: sending function arguments to recursive function calls, Gauthier Östervall, 2013/05/17
- Re: sending function arguments to recursive function calls, Dmitry Gutov, 2013/05/17
- RE: sending function arguments to recursive function calls, Drew Adams, 2013/05/17
- Re: sending function arguments to recursive function calls, Dmitry Gutov, 2013/05/19
- RE: sending function arguments to recursive function calls, Drew Adams, 2013/05/21
- Message not available
- Re: sending function arguments to recursive function calls, Pascal J. Bourguignon, 2013/05/19
- Re: sending function arguments to recursive function calls,
Dmitry Gutov <=
- Message not available
- Re: sending function arguments to recursive function calls, Pascal J. Bourguignon, 2013/05/20
- Re: sending function arguments to recursive function calls, Pascal J. Bourguignon, 2013/05/07
- Message not available
- Re: sending function arguments to recursive function calls, Pascal J. Bourguignon, 2013/05/07
- Re: sending function arguments to recursive function calls, Stefan Monnier, 2013/05/08
Re: sending function arguments to recursive function calls, Stefan Monnier, 2013/05/04