Ahhh, I see you read the small print; excellent. I'll resist participating in dialogues about my abberant fascinations, we banned someone for that yesterday. Anyway ...
For those that may desire more illumination about variable scope consider the following (observe variable 'temp') ...
;; demo function
;; works with variable
;; temp appropriate to
;; lexical scope
(defun ConsXToVariableTemp ( x )
(princ
(strcat
"=> temp : "
(vl-princ-to-string
(setq temp
(cons x temp)
)
)
"\n"
)
)
)
;; separate function definition
;; with nested (local) functions
(defun c:Test ( / implicit explicit temp )
;; variable temp is local to function
;; because it is an argument to the
;; function
(defun implicit ( temp )
(ConsXToVariableTemp 1)
)
;; variable temp is local to function
;; because it is formally declared as
;; having local scope in the function
;; definition
(defun explicit ( / temp )
(setq temp '(7 8 9))
(ConsXToVariableTemp 6)
)
;; call function implicit, passing a
;; small list as the parameter
(implicit '(2 3 4))
;; call function explicit, no parameters
(explicit)
;; define and invoke an annonymous function
;; that explicitly declares temp as having
;; local scope; parameterless
( (lambda ( / temp )
(setq temp '(b c d))
(ConsXToVariableTemp 'a)
)
)
;; define and invoke an annonymous function
;; that implicitly declares temp as having
;; local scope because it's a parameter
( (lambda (temp)
(ConsXToVariableTemp '+)
)
'(- * /) ;; passed as the parameter
)
;; call ConsXToVariableTemp directly after
;; setting variable temp that has scope local
;; to function c:Test
(setq temp '(@ # $))
(ConsXToVariableTemp '!)
;; shhh
(princ)
)
;; before we call c:Test let's set
;; global variable 'temp' to something
(setq temp "Lexical Scope, whoa.")
;; show whats bound to temp
!temp
=> "Lexical Scope, whoa."
;; perform the test run
(c:Test)
=> temp : (1 2 3 4)
=> temp : (6 7 8 9)
=> temp : (A B C D)
=> temp : (+ - * /)
=> temp : (! @ # $)
;; show whats bound to temp
!temp
=> "Lexical Scope, whoa."
Kerry is 100% correct - code like this can be difficult to debug if you lose track of the scope. As such I normally avoid it myself and do not recommend it as normal practice.
And now for something different ...
(defun ConsToXQuotedVariable ( x QuotedVariable )
(set QuotedVariable
(cons x
(eval QuotedVariable)
)
)
)
(setq temp '(2 3 4))
!temp
=> (2 3 4)
(ConsToXQuotedVariable 1 'temp)
!temp
=> (1 2 3 4)
Cheers.