The Declare Function
I spent the majority of my day unable to get mini-max down. I had a get-best-move function that was calling on it, and then a minimizer, and a maximizer function. But something in my head kept stalling me. I don’t know what it was, but during my pain, I did learn a bit about a function I haven’t used before.
declare
The declare function is a way to declare the existince of a variable, without having to define it at the moment. This is particularly useful when you have functions that need to reference each other (such as my maximizer function calling the mini-max function in which it was originally called). By declaring the variables beforehand you can define them in any order you’d like without running into issues where one is not yet defined when referenced.
The syntax is simple.
(declare <variable name here>)
You can also declare multiple in one argument.
(declare <var1> <var2> <var-nth>)
It is to be noted that declare only makes the compiler aware that the variables exist, it does not define them for you, you still need to do that yourself.