title: unbound-variable error when trying to determine OS in emacs lisp with slime
body: <p>I am trying to determine the system's OS with a lisp program running on emacs+slime, using code from the internet (because I am a newbie in lisp). In particular, I use the following code:</p>
  <pre><code>;; check OS type
  (cond
   ((string-equal system-type &quot;windows-nt&quot;) ; Microsoft Windows
    (progn
      (message &quot;Microsoft Windows&quot;) )
    )
   ((string-equal system-type &quot;darwin&quot;)   ; Mac OS X
    (progn
      (message &quot;Mac OS X&quot;)
      )
    )
   ((string-equal system-type &quot;gnu/linux&quot;) ; linux
    (progn
      (message &quot;Linux&quot;) )
    )
  )
  </code></pre>
  <p>(I found this code in <a href="http://ergoemacs.org/emacs/elisp_determine_OS_version.html" rel="nofollow noreferrer">this website</a>.)</p>
  <p>I put the code above in a file (02.lisp) and after the last parenthesis I press C-c C-c to compile it. But this gives me the following error:</p>
  <blockquote>
  <p>Unbound variable: SYSTEM-TYPE</p>
  <pre><code>   [Condition of type UNBOUND-VARIABLE]
  </code></pre>
  </blockquote>
  <p>Same thing happens when I put the code directly in the top level. This happens both in my Windows computer where I am running the lisp program in a lispbox installation of emacs+slime, and in my Linux computer where I am running the lisp program in a standard debian installation of emacs+slime via apt-get.</p>
  <p>Why am I getting this error, and what would be the right way to find out, in common lisp (so inside the .lisp program) which operating system it is in? Thank you very much in advance, and please keep in mind that I am very new to lisp+emacs, so apologies if this is a silly/confused question.</p>
  <p><em>----Edit to add more details on my problem:</em></p>
  <p>I want to be able to do this within the lisp program (02.lisp) because I would like to be able to load a database via this 02.lisp. So the code I was planning to actually use with the above way (which I now see is completely wrong, thanks to jch's answer), is the following:</p>
  <pre><code>(cond
   ((string-equal system-type &quot;windows-nt&quot;) ; Microsoft Windows
    (progn
      (message &quot;Microsoft Windows&quot;) 
      (with-open-file (in &quot;g:/lisp programs/implications.db&quot;)
        (with-standard-io-syntax
      (setf *db* (read in))))
  )
    )
    ((string-equal system-type &quot;gnu/linux&quot;) ; linux
    (progn
      (message &quot;Linux&quot;)
      (with-open-file (in &quot;/media/NANO16GB/lisp programs/implications.db&quot;)
        (with-standard-io-syntax
      (setf *db* (read in)))
      )
    )))
  </code></pre>
  <p>I want to have this because I work on this program in two computers, depending where I am, and I want the program to load a database from my usb stick.</p>
  <p>So the question is, how to determine which OS am I running the program in, within the .lisp program, in order to use the appropriate code to load the database. Of course, a different code, that helps me load the database in my situation, would help, but by now I'm interested in determining the OS from within the .lisp program, just because I can't find out how to do it.</p>
  <p><em>-----------Solved: thanks to jch's comments, I got to the following code that works:</em></p>
  <pre><code>(cond
   ((string-equal (software-type) &quot;Microsoft Windows&quot;) ; Microsoft Windows
    (progn
      (format t &quot;Microsoft Windows&quot;) 
      (with-open-file (in &quot;g:/lisp programs/implications.db&quot;)
        (with-standard-io-syntax
      (setf *db* (read in))))
  )
    )
    ((string-equal (software-type) &quot;Linux&quot;) ; linux
    (progn
      (format t &quot;Linux&quot;)
       (with-open-file (in &quot;/media/NANO16GB/lisp programs/implications.db&quot;)
        (with-standard-io-syntax
      (setf *db* (read in)))
      )
    )))
  </code></pre>