Question

I use SLIME/SBCL/Emacs and Quicklisp on Ubuntu Raring. I have the function defined below. I would like to add to my Lisp library's top .lisp file, i.e., the one every other one depends on, so that I can use it in all the functions I write with my library by just adding (update-swank) to a function instead of having to add the entire function below to each piece of code that uses it.

(defun update-swank ()
   "Grabs SWANK connections and tells it to handle requests. 
    Call this every loop in the main loop of your program"
   (continuable
     (let ((connection (or swank::*emacs-connection*
               (swank::default-connection))))
       (when connection
     (swank::handle-requests connection t)))))

When I do this and restart emacs, loading my library in the process because I have the asdf:load-op in my .sbclrc file, I get a

READ error during COMPILE-FILE:
;   
   ;     Package SWANK does not exist.

in inferior lisp, and SLIME is stuck polling because the library doesn't load because in my current setup SLIME/SBCL doesn't know what swank is at the time the .lisp file that update-swank is in is loaded. I tried adding (in-package :swank) to the file that update-swank is in, but got

The name "SWANK" does not designate any package.

in inferior lisp when my library is loaded at emacs startup.

I searched through CEPL (where i got update-swank from https://github.com/cbaggers/cepl/blob/master/cepl-utils.lisp) and then copied what the creator of CEPL did and exported the function in my packages.lisp. I made sure the function was added like he did on line 20 of cepl-utils here https://github.com/cbaggers/cepl/blob/master/cepl-utils.lisp......I load my library btw with

(asdf:operate 'asdf:load-op :cl-test)
(in-package #:cl-test)

in my .sbclrc file which i assume is loaded before my .emacs file loads slime at emacs start up (i have (slime) in my .emacs file) ...I just tested removing the adsf:load-op and in-package and from my .sbclrc and running the asdf:load-op after slime/swank has been loaded and what i've been trying to do here worked with no error....but i would like to be able load my library automatically at emacs startup and the way i usually do that is by adding the asdf:load-op to my .sbclrc....If someone could tell me another way to load my library automatically at emacs startup after swank has been loaded that would answer this ?

Was it helpful?

Solution 2

This was made to sit inside the main loop of the game/realtime-demo as that was what was blocking the repl from updating. Luckily we are in control of the loop so that is easy. Now you are wanting to use this in your library (probably with opencv) so you need to identify what is blocking the update, this is generally some kind of 'main loop' if you have access to the main loop then call update-swank from in there.

If the main loop is being controlled by a foreign library then perhaps you can put it in a function that gets called every 'loop'. All you really need is it to be called often enough that the repl feels responsive.

Other than that you can try changing the settings of swank to run on a separate thread though I have no experience doing that so I cant tell you how well that would work.

You can see it inside the main loop in the (run-demo) function of this example

Also I talk about it in this video. Though albeit perhaps not in enough detail :)

The fact you are getting "swank does not exist" is very odd. It suggest that swank is not loaded, but if you are using slime then swank must be there!

p.s. Remember that this is for use with Slime or Slim, which means you are using them with emacs or vim. If you are not using Slime+emacs or Slim+vim this function will not work!

[EDIT] Ok so I duplicated your issue by putting (ql:quickload :cepl) at the end of quicklisp's setup.lisp file. This gave me the 'Package SWANK does not exist'. One quick way to address this is to specify swank as a dependency in your project's asd file. So for example:

(asdf:defsystem #:cepl
  :serial t
  :depends-on (#:cl-opengl
               #:swank     ;;<---HERE
               #:lbm-sdl
               #:varjo
               #:cl-utilities
               #:cl-ppcre
               #:symbol-munger
               #:classimp
               #:temporary-file
               #:md5)
  :components ((:file "package")
               (:file "maths/base-maths")
               (:file "base-macros")
               ;; (:file "base-lispbuilder")
               (:file "cepl-utils")

Hope it helps :)

OTHER TIPS

If there is not a package defined in a running Lisp, then this package can't be used. First you need to define the package and then you can read symbols from that package. Packages are not created when CL tries to read a symbol from an unknown package.

If (find-package "FOO") returns NIL, then you can not read a symbol like FOO::BAR.

Two solutions to that are:

  • execute the package definition before a symbol from that package is read

  • remove the symbols from the source code:

Example:

foo::*bar*

replace with

(symbol-value (find-symbol "*BAR*" "FOO"))

Above finds the symbol at runtime and retrieves the symbol value.

Also:

(foo::bar :baz t)

replace with

(funcall (symbol-function (find-symbol "BAR" "FOO")) :baz t)

Above finds the symbol at runtime, retrieves the function and calls it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top