Variables

Submitted by Phaul on Mon, 2006-09-04 13:25.
::
declare The declare keyword declares the particular name in the scope that contains it, and assigns NIL value to it. Important to note here that the declare statements are interpreted only once, so if the execution flow goes through it twice the value of the variable is set only during the first execution. This is similar to the C programming language's static variable initialization. This allows us to write a code like this:
(declare onlyonce)
(if (not onlyonce)
   (progn
      (set onlyonce 1)
      ; this code is interpreted only once
   ); progn
); if
progn, func There are two keywords that declare new variable scope, these are progn and func. The scope begins with the keyword and ends with the corresponding `)' mark. You can't use a variable - even inside the same scope before it's declaration. The same variable can't be declared in the same scope twice, but in a subscope. In this case the second variable overlaps the first, starting from its declaration point, ending at the subscope's end.
(progn
   (declare x)    ; the first x
   (progn         ; the start of the inner scope
      (print x)   ; this prints the first x
      (declare x) ; this declares the second x 
      (print x)   ; this prints the second x
   )              ; end of the inner scope
   (print x)      ; this is the first x again 
); progn - end of the outer scope
; (print x) gave error : x not declared here