Created
          February 8, 2017 18:42 
        
      - 
      
- 
        Save svetlyak40wt/069c8e8ed341d1a6ca21250662d89c9d to your computer and use it in GitHub Desktop. 
    Common Lisp. Dynamic variable binding using defun's lambda expression.
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | (defvar *foo* nil) | |
| (defun minor () | |
| (format t "~&*foo* in minor: ~a~%" *foo*)) | |
| (defun bar (&key ((:baz *foo*) 42)) | |
| (format t "~&*foo* in bar: ~a~%" *foo*) | |
| (minor)) | |
| (progn | |
| (format t "~&*foo* in global scope: ~a~%" *foo*) | |
| (bar :baz 'checking)) | |
| ;; This code outputs: | |
| ;; *foo* in global scope: NIL | |
| ;; *foo* in bar: CHECKING | |
| ;; *foo* in minor: CHECKING | |
| ;; Here *foo* behaves as a special variable, | |
| ;; which makes this bar definition almost equivalent to | |
| (defun bar (&key (baz *foo*)) | |
| (let ((*foo* baz)) | |
| (format t "~&*foo* in bar: ~a~%" *foo*) | |
| (minor))) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment