Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading Packages in a Progn in Common Lisp

I am trying to make a simple form that will automate the loading of Slynk on an image.

So far, I have this:

(progn 
    (load "/home/user/asdf.lisp")
    (format t "~% Loaded ASDF")
    (push "/home/user/.emacs.d/elpa/sly-20180708.712/slynk/" asdf:*central-registry*)
    (format t "~% Added SLYNK path to ASDF:*CENTRAL-REGISTRY*")
    (asdf:load-system :slynk)
    (format t "~% Loaded ASDF system")
    (slynk:create-server :port 4007  :dont-close t)
    (format t "~% Created SLYNK server on port 4007")
    (setf slynk:*use-dedicated-output-stream* nil)
    (format t "~% Set *USE-DEDICATED-OUTPUT-STREAM* to NIL"))

The issue is that whenever I try to evaluate this form at the REPL, I get the following error:

Error: "ASDF" is not a known package.

Restart actions (select using :continue):
 0: Return NIL
 1: Return to Top Level (an "abort" restart).
 2: Abort entirely from this (lisp) process.
[1] CL-USER(4): 

No prints yet appear prior to that point. That is, it seems to error on the first push line. My understanding is that it has not yet loaded the package and tries to refer to its symbol.

How can I change the form to make it work? There are similar situations lower in the form.

P.S. When each line is executed by itself in the given order, everything works perfectly.

like image 390
MadPhysicist Avatar asked Dec 02 '25 14:12

MadPhysicist


1 Answers

The error comes from read as it tries to parse the whole progn form and sees the asdf: package prefix.

You must load asdf before the reader sees the code with the asdf: package prefix and load slynk before you use the :slynk prefix, in other words, feed your progn forms to Lisp one by one (as you say in your PS).

Another way is to put everything inside your progn in a separate file and load it. You would also want to make "20180708.712" and 4007 variables, e.g.,

(defvar *sly-version* "20180708.712")
(defvar *slynk-port* 4007)
(load "load-and-start-slynk.lisp")

and in load-and-start-slynk.lisp:

(load "/home/user/asdf.lisp")
(format t "~% Loaded ASDF")
(push (concatenate 'string "/home/user/.emacs.d/elpa/sly-"
                   *sly-version* "/slynk/")
      asdf:*central-registry*)
(format t "~% Added SLYNK path to ASDF:*CENTRAL-REGISTRY*")
(asdf:load-system :slynk)
(format t "~% Loaded ASDF system")
(slynk:create-server :port *slynk-port* :dont-close t)
(format t "~% Created SLYNK server on port ~D" *slynk-port*)
(setq slynk:*use-dedicated-output-stream* nil)
(format t "~% Set *USE-DEDICATED-OUTPUT-STREAM* to NIL")

PS. Just to show how to abuse Lisp power, here is how to do what you are trying to do:

(defun load-and-start-slynk (port version)
  (load "/home/user/asdf.lisp")
  (format t "~% Loaded ASDF")
  (push (concatenate 'string "/home/user/.emacs.d/elpa/sly-" version "/slynk/")
        (symbol-value (find-symbol "*CENTRAL-REGISTRY*" '#:asdf)))
  (format t "~% Added SLYNK path to ASDF:*CENTRAL-REGISTRY*")
  (funcall (find-symbol "LOAD-SYSTEM" '#:asdf) :slynk)
  (format t "~% Loaded ASDF system")
  (funcall (find-symbol "CREATE-SERVER" '#:slynk) :port port :dont-close t)
  (format t "~% Created SLYNK server on port ~D" port)
  (setf (symbol-value (find-symbol "*USE-DEDICATED-OUTPUT-STREAM*" '#:slynk)) nil)
  (format t "~% Set *USE-DEDICATED-OUTPUT-STREAM* to NIL"))

Do not do this.

like image 195
sds Avatar answered Dec 05 '25 20:12

sds



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!