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.
One could imagine that we can write:
But that does usually not work, because we can't read symbols when their package is not existing and some packages are implementation/library/application specific. Packages are not created at read time in a lazy/automatic fashion.
In Common Lisp, reading a symbol of a package, which does not exist, leads to an error:
In your example
sb-thread:make-mutex
is a symbol which makes sense in SBCL, but not in Allegro CL. Additionally the packageSB-THREAD
does not exist in Allegro CL. Thus Allegro CL needs to be protected from reading it. In this case, the symbolsb-thread:make-mutex
will only be read, if the the featuresb-thread
is present on thecl:*features*
list. Which is likely only for SBCL, or a Lisp which claims to havesb-threads
available.The feature expressions here prevents the Lisp from trying to read symbols with unknown packages - the packages are unknown, because the respective software is not loaded or not available.