common-lispswank

Can i load swank lazily?


The following code works but i have to load swank no matter whether i need it or not.

(ql:quickload :swank)
(defun swank ()
    (swank:create-server :port 4005 :donot-close t))

If i move "(ql:quickload :swank)" into function swank, then CL will not find package swank.

Sincerely!


Solution

  • Remember that reading is a separate phase in CL. First a form is read, then it is executed. When the reader read the DEFUN form, it didn't recognize the SWANK:CREATE-SERVER symbol because, at that point, QL:QUICKLOAD had not been executed yet. The solution is to use INTERN.

    (defun swank ()
      (ql:quickload :swank)  
      (funcall (intern (string '#:create-server) :swank) :port 4005 :dont-close t))