Today I began by updating my Tip Calculator program to use a let*
instead of a let
when declaring local variables in calculation of the tip. This took about two minutes.
Next, I finished reading the chapter on variables in PCL. In CL, there are two different ways of declaring global variables: defvar
and defparameter
. defvar
is used if you want to make sure not to overwrite a value already established by the code just because you're updating the code. This is because defvar
only sets the value of a variable if it's undefined. defparameter
sets the value no matter what. With dynamic/global variables in CL, you're able to make them temporarily store the value for the execution of some form and then automatically go back to the former value. This is good if you have a global variable that has some default value most of the time but want it to be something else for a specific situation. ordinarily, you'd have to remember to change the value back. But CL takes care of this for you.
Constants are defined using defconstant
. It's conventional to begin the naming of constants with a +
.
The macro for variable assignment is setf
which is actually dealing with the setq
special operator behind the scenes. There are also increment/decrement operators: incf
and decf
. There are a bunch of other macros used for modifying variables (modify macros) such as push
and pop
for lists. Also other useful ones like rotatef
and shiftf
which move values between variables.
That's it for today. Tomorrow I'm going more in-depth on macros.