all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Hongxu Chen <leftcopy.chx@gmail.com>
To: help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: add-to-list with lexical variables
Date: Sat, 08 Jun 2013 20:39:16 +0800	[thread overview]
Message-ID: <87txl8u68b.fsf@gmail.com> (raw)


Hi list,

  I am writing a snippet to add element into environment variables, and
  it is written as below:

#+BEGIN_SRC elisp  
(defun no-dup-add-env-ele (env env-ele-string)
   (let* ((env-separator (if (string-equal system-type "windows-nt") ";" ":"))
     (env-list (split-string (getenv env) env-separator)))
     (if (string-match-p env-separator env-ele-string)
        (dolist (env-ele (split-string env-ele-string env-separator))
                (add-to-list 'env-list env-ele)) 
     (add-to-list 'env-list env-ele-string))
     (setenv env (mapconcat 'identity env-list ":"))))
#+END_SRC

1. when I set `lexical-binding' to t and byte-compile the file, it
would report this error:

    add-to-list cannot use lexical var `env-list'

2. And when I using `lexical-let*' instead, there would be an warning:

    Warning: assignment to free variable `env-list'

3. However after resetting `lexical-binding' to nil, byte-compiles well.

So what are the differences?

Thanks,
Hongxu Chen




             reply	other threads:[~2013-06-08 12:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-08 12:39 Hongxu Chen [this message]
2013-06-08 14:00 ` add-to-list with lexical variables Pascal J. Bourguignon
2013-06-08 15:19   ` Hongxu Chen
2013-06-08 20:34     ` Stefan Monnier
     [not found]   ` <mailman.1222.1370704797.22516.help-gnu-emacs@gnu.org>
2013-06-08 17:08     ` Pascal J. Bourguignon
2013-06-09  3:18       ` Hongxu Chen

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=87txl8u68b.fsf@gmail.com \
    --to=leftcopy.chx@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /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.