A simple test on the command line… Write or paste the yellow stuff and try to understand.
On the command line… | What is it? |
(defun test ( / foobar) (setq foobar T)) | DEfine a FUNction “test ” that sets a variable “foobar ” to T (True). No need to say you have to finish with an enter. |
TEST | Return value of last statement (defun ). |
!foobar | Put ! before the name of a variable to get its value… |
nil | We have defined the function only, foobar is nil yet. |
(test) | Run function TEST . |
T | Return value of last statement (setq …). |
!foobar | What is value foobar ? |
nil | Foobar is nil because it is in part ( / foobar) , saying: Set this to nil after running the function. |
!test | And the function itself? |
< #x33 @fffc51876> | It survived and is still loaded under this value. |
(setq test nil) | What happens if we set the function name to nil ? |
nil | Exactly, test is nil , test simply doesn’t exist any more. Setting variables to nil simply destroys, kills, variables from memory. |
!test | Double check… |
nil | And confirmed. |
(defun test ( / ) (setq foobar T)) | Define function “test ” again, but with ( / ) instead of ( / foobar) . |
TEST | Return value… |
(test) | Run function TEST . |
T | Return value… |
!foobar | What is value foobar ? |
T | Now foobar is not nil because it is not in part ( / ) . This can be handy, foobar survived the function and can be used again for something else. However, it can be polluting and annoying and create errors when it is expected to be not existing. |
!test | And the function itself? |
< #x33 @fffc51896> | Still loaded, newly defined, different value. |
(setq test nil) | What happens if we set the function name to nil ? |
nil | Gone! |
!test | Check… |
nil | Yes, gone. |
!foobar | And foobar ? |
T | Still active 🙂 |