Recently I tried to read code about cl-mysql, but got stuck with the #+.
Tried to google it, but not work, so turn to here
(defun make-lock (name)
#+sb-thread (sb-thread:make-mutex :name name)
#+ecl (mp:make-lock :name name)
#+armedbear (ext:make-thread-lock)
#+ (and clisp mt) (mt:make-mutex :name name)
#+allegro (mp:make-process-lock :name name))
And looks like it is for different backend lisp compiler. But still no idea why write something like this. Anyone can help me make it clear, thx.
#+is a reader-macro that checks if a keyword is in the special variable*FEATURES*. If it isn't there, the following form will be skipped over (by the reader; the compiler will never see it). There is also#-which does the opposite.There are some things that aren't part of the Common Lisp standard, but are important enough that all (or most) implementations provide a non-standard extension for them. When you want to use them in code that needs to work on multiple implementations, you have to use read-time conditionals to provide the correct code for the current implementation. Mutexes (and threads in general) are one of those things.
Of course there may be features provided by third party libraries as well. The contents of
*FEATURES*will look something like this:So if you wanted to write code that depends on Quicklisp for example, you could use
#+quicklisp. If you wanted code that is only run if Quicklisp is not available, you'd use#-quicklisp.You can also use a boolean expression of features. For example,
would print
Foo!on either SBCL or ECL.would only print
Bar!on SBCL that has Quicklisp available.