all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* add-to-list with lexical variables
@ 2013-06-08 12:39 Hongxu Chen
  2013-06-08 14:00 ` Pascal J. Bourguignon
  0 siblings, 1 reply; 6+ messages in thread
From: Hongxu Chen @ 2013-06-08 12:39 UTC (permalink / raw)
  To: help-gnu-emacs


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




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-06-09  3:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-08 12:39 add-to-list with lexical variables Hongxu Chen
2013-06-08 14:00 ` 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

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.