खोज…


वैश्विक विशेष चर हर जगह विशेष हैं

इस प्रकार ये चर गतिशील बंधन का उपयोग करेंगे।

(defparameter count 0)
;; All uses of count will refer to this one 

(defun handle-number (number)
  (incf count)
  (format t "~&~d~%" number))
  
(dotimes (count 4)
  ;; count is shadowed, but still special
  (handle-number count))
  
(format t "~&Calls: ~d~%" count)
==>
0
2
Calls: 0

इस समस्या से बचने के लिए विशेष चर अलग-अलग नाम दें:

(defparameter *count* 0)

(defun handle-number (number)
  (incf *count*)
  (format t "~&~d~%" number))
  
(dotimes (count 4)
  (handle-number count))
  
(format t "~&Calls: ~d~%" *count*)
==>
0
1
2
3
Calls: 4

नोट 1: एक निश्चित दायरे में एक वैश्विक चर को गैर-विशेष बनाना संभव नहीं है। वैरिएबल को लेक्सिकल बनाने की कोई घोषणा नहीं है।

नोट 2: special घोषणा का उपयोग करके स्थानीय संदर्भ में एक विशेष चर घोषित करना संभव है। यदि उस चर के लिए कोई वैश्विक विशेष घोषणा नहीं है, तो घोषणा केवल स्थानीय स्तर पर है और इसे छायांकित किया जा सकता है।

(defun bar ()
  (declare (special a))
  a)                       ; value of A is looked up from the dynamic binding

(defun foo ()
  (let ((a 42))            ; <- this variable A is special and
                           ;    dynamically bound
    (declare (special a))
    (list (bar)
          (let ((a 0))     ; <- this variable A is lexical
            (bar)))))


> (foo)
(42 42)


Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow