As an ArgoUML contributor I'm going to blog my activities here, so that they may draw interest by other developers or help other developers when doing tasks similar to what I've done. AND(!) the grand vision that makes an Argonaut what he is, TO THRIVE IN THE BIG DANGEROUS WORLD, TAKING THE Argo TO A GOOD SHORE ;-))

Thursday, May 07, 2009

Common Lisp dynamic variables

One thing that Common Lisp has which is very powerfull is its dynamic variables. The following code ilustrates the concept:

CL-USER(124): (defvar *x* "Hello") ; *x* is a dynamic variable*X* 
CL-USER(125): (progn
                (let ((*x* "Ola")) ; establishes a dynamic environment for *x*
                  (format t "~a~%" *x*)
                  (setf *x* "Ciao")
                  (format t "~a~%" *x*)) ; end of the dynamic environment
                (format t "~a~%" *x*)) ; back to the initial dynamic environment
                                       ; *x* assumes its original binding 

Now if this is used with multiple processing and/or closures you get very powerful ways to separate things and a great amount of flexibility almost for nothing.

No comments:

Reader Shared items