define-symbol-macro 2
In lisp it is quite common (no pun intended) to use dynamic variables for frequently accessed resources, such as writing to the data store, to avoid being passed around to functions throughout the program. The convention is to start and end the variable with an asterisk.
I was working on a program where I need to know the current day throughout the application. I decided to define a dynamic variable called *current-day*. This sounded like a good idea because the value seemed fairly static. One thing I wasn't thinking about at the time I defined the variable is that the variable actually gets its value when the program is initialized. So the value will only be right the first day, and perpetually wrong as long as the program has not been restarted.
I have a couple options here. I could just change *current-day* to a function instead. While this is a sound approach, it might not be practical if current-day is scattered across various files. Second option is to use define-symbol-macro. I can bind a function that calculates the current day to the current-day variable, so every time the variable is evaluated the function will be invoked.
(define-symbol-macro *current-day* (current-day))If, for whatever reason, the function is updated, *current-day* will receive the "new" version of the function. Another pleasant side effect of the define-symbol-macro is that the caller cannot change the value of *current-day*. An error will be signaled (assuming (SETF CURRENT-DAY) is not defined)
Some may argue the use of define-symbol-macro is confusing because *current-day* looks like a variable, but in reality it acts more like a function. The caller should just call the function that figures out the current day instead of creating a dynamic variable for it. The argument is valid, but there might be cases where you are building a library and do not want to break external code. Define-symbol-macro provides a nice abstraction over the dynamic variable.

There's a teensy glitch when you say "(assuming setf is not defined)":
SETF is always defined as soon as you use the CL package, so it must be something like "assuming (SETF FUN) is not defined". :)
Leslie
Good catch Leslie.