all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Jambunathan K <kjambunathan@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Error: add-to-list cannot use lexical var ...
Date: Tue, 14 Aug 2012 08:48:03 -0400	[thread overview]
Message-ID: <jwvobmdtzj7.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87mx1yoxkm.fsf@gmail.com> (Jambunathan K.'s message of "Tue, 14 Aug 2012 10:54:25 +0530")

>     (let (l)
>       (add-to-list 'l "testing"))

Functions like add-to-list and `set' rely on an equivalence between
symbol objects and variables which is incompatible with lexical scoping.

> You will see an error like.
>     vc-dir.el:54:1:Warning: Unused lexical variable `l'
>     vc-dir.el:54:7:Error: add-to-list cannot use lexical var `l'

> I should say the results are not along the expected lines.  Can someone
> explain it to me?

When interpreted, add-to-list could be made to work by looking up the
lexical environment, searching for the binding of `l'.
But when byte-compiled there's no such option because the byte-code
doesn't even remember that the local var was named `l'.

You can use CL's pushnew (with :test 'equal) instead.


        Stefan



      reply	other threads:[~2012-08-14 12:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-14  5:24 Error: add-to-list cannot use lexical var Jambunathan K
2012-08-14 12:48 ` Stefan Monnier [this message]

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=jwvobmdtzj7.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=kjambunathan@gmail.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.