all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dgutov@yandex.ru>
To: "Pascal J. Bourguignon" <pjb@informatimago.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: sending function arguments to recursive function calls
Date: Mon, 20 May 2013 23:31:40 +0400	[thread overview]
Message-ID: <87obc5v46b.fsf@yandex.ru> (raw)
In-Reply-To: <878v3aofcy.fsf@kuiper.lan.informatimago.com> (Pascal J. Bourguignon's message of "Sun, 19 May 2013 22:59:41 +0200")

"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.



  reply	other threads:[~2013-05-20 19:31 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-04 13:01 sending function arguments to recursive function calls Gauthier Östervall
2013-05-04 15:30 ` Drew Adams
2013-05-07 11:25   ` Gauthier Östervall
2013-05-07 14:04     ` Drew Adams
2013-05-08 12:21       ` Stefan Monnier
2013-05-09  8:35         ` Gauthier Östervall
2013-05-09 12:23           ` Stefan Monnier
2013-05-12 13:19             ` Gauthier Östervall
2013-05-13 14:55               ` Stefan Monnier
2013-05-17 12:20                 ` Gauthier Östervall
2013-05-17 12:26                   ` Dmitry Gutov
2013-05-17 14:31                     ` Drew Adams
2013-05-19 16:57                       ` Dmitry Gutov
2013-05-21 16:34                         ` Drew Adams
     [not found]                       ` <mailman.70.1368982677.22516.help-gnu-emacs@gnu.org>
2013-05-19 20:59                         ` Pascal J. Bourguignon
2013-05-20 19:31                           ` Dmitry Gutov [this message]
     [not found]                           ` <mailman.94.1369078320.22516.help-gnu-emacs@gnu.org>
2013-05-20 19:55                             ` Pascal J. Bourguignon
2013-05-07 14:32     ` Pascal J. Bourguignon
     [not found]     ` <mailman.25279.1367935468.855.help-gnu-emacs@gnu.org>
2013-05-07 14:55       ` Pascal J. Bourguignon
2013-05-08 12:25         ` Stefan Monnier
2013-05-05  1:22 ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87obc5v46b.fsf@yandex.ru \
    --to=dgutov@yandex.ru \
    --cc=help-gnu-emacs@gnu.org \
    --cc=pjb@informatimago.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.