Search code examples
modulelispcommon-lispx11clisp

How do I use CLX/XLIB from Common Lisp after installing it from my package manager?


I'm trying to use CLX while learning common lisp, because I figure it's more effective to learn if I have an actual, tangible, practical result. Unfortunately, I can't get CLX to work. I followed the first bit of this tutorial, after installing the clisp and clisp-module-clx packages in debian.

I think I'm just horribly misunderstanding clisp's package / module / etc. loading system, but I can't find any resources for how to do this.

foo.lisp:

(defun pop-up-window (life-time &optional (host ""))
  (let* ((display (xlib:open-display host))
         (screen (first (xlib:display-roots display)))
         (root-window (xlib:screen-root screen))
         (my-window (xlib:create-window
                      :parent root-window
                      :x 0
                      :y 0 
                      :width 200
                      :height 300)))
    (xlib:map-window my-window)
    (xlib:display-finish-output display)
    (format t "it should be here ~%")
    (sleep life-time)
    (xlib:destroy-window my-window)
    (xlib:close-display display)
)

(pop-up-window 10)

output: there is no package with name "XLIB"

Edit:

I tried (require "clx") at the start of my code, but I get #<PACKAGE COMMON-LISP> is locked.


Solution

  • The CLX system was most likely not installed. You could download the archive yourself and configure ASDF to load the system, but the easiest route is to first install Quicklisp. Then, you can execute:

    (ql:quickload :clx)
    

    This downloads, compiles and loads the desired system and all its dependencies. This step should be executed each time you restart your Lisp environment. As soon as you need more than one libraries, you should also define your own system (for example in ~/quicklisp/local-projects/) and load that one instead.