[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
add-to-list with lexical variables
From: |
Hongxu Chen |
Subject: |
add-to-list with lexical variables |
Date: |
Sat, 08 Jun 2013 20:39:16 +0800 |
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
- add-to-list with lexical variables,
Hongxu Chen <=