Re: Passing Global Variables Urgh.
- From: Ralf Mattes <rm@xxxxxxxxxxxxxx>
- Date: Thu, 30 Aug 2007 12:21:26 +0000 (UTC)
Just as an addition to the other posts (since noone cared
to sove your "problem"):
(defvar *x* "blub")
;;; We avoid 'setq' since we already get a symbol
;;; and don't need to quote it ...
(defun modify-it (symbol)
(set symbol "newer blub"))
;;; Ok, we want to pass a _symbol_ so we better
;;; protect *x* from being evaluated before being
;;; passed th modify-it - 'quote' to the rescue ...
(modify-it (quote *x*))
; => "newer blub"
;;; ... or, as a shorthand
(modify-it '*x*)
; => "newer blub"
;;; but beware!
(let ((honk 42))
(warn "Value uf honk is ~A" honk)
(modify-it 'honk)
honk)
;;; Evaluate this expression twice and watch the
;;; warning.
;;; strange, eh?
;;; Not really: or function doesn't "see" the
;;; local bound honk and hence can't modify it.
;;; It'll try to modify the globally visible honk -
;;; if honk doesn't exist asa global (special) variable
;;; all sorts of strange things might happen ...
HTH RalfD
.
- References:
- Passing Global Variables Urgh.
- From: landspeedrecord
- Passing Global Variables Urgh.
- Prev by Date: Re: Passing Global Variables Urgh.
- Next by Date: Re: Lisp Interpreter in ActionScript 3
- Previous by thread: Re: Passing Global Variables Urgh.
- Index(es):