fukamachi/quri

Please provide a load form for URIs

ralph-schleicher opened this issue · 5 comments

Hi,

when compiling the form

(defconstant root-uri (quri:uri "/")
  "Root path URL.")

Clozure CL fails with an error message:

Error: No MAKE-LOAD-FORM method is defined for #<QURI.URI:URI />

Adding the following code snippet fixes the error.

;; Make Clozure CL happy.
(defmethod make-load-form ((object quri:uri) &optional environment)
  (make-load-form-saving-slots object :environment environment))

Would be nice if you can add something equivalent upstream. Thank you.

Observed with quri-20230618 from Quicklisp.

aadcg commented

Hello @ralph-schleicher. I can't reproduce it on CCL 1.12.1 and quri version 0.7.

Sorry, the term compiling was too inaccurate. I can only reproduce the error when the form is part of a system loaded by Quicklisp. Up to now I was not able to create a minimal environment triggering the error. However, if you search the net for "make-load-form clozure cl", you'll find more use cases. See, for example,
https://stackoverflow.com/questions/346695/no-make-load-form-error-with-openmcl-common-lisp

Here is a minimal system to trigger the error:

File t.asd:

(in-package :asdf-user)

(defsystem "t"
  :description "A test system."
  :depends-on (:quri)
  :components ((:file "t")))

File t.lisp:

(in-package :common-lisp-user)

(defmacro defconst (name value &optional doc)
  `(defconstant ,name (if (boundp ',name) (symbol-value ',name) ,value)
     ,@(when doc (list doc))))

(defconst root-uri (quri:uri "/")
  "Root path URL.")

(defun root-uri ()
  "Return the root path URL."
  root-uri)

File loader.lisp:

(in-package :common-lisp-user)

;; Clear cache.
(let* ((absolute-directory (pathname-directory (uiop:getcwd)))
       (relative-directory (cons :relative (rest absolute-directory)))
       (there (asdf:resolve-location
               (list :user-cache (make-pathname :directory relative-directory)))))
  (uiop:delete-directory-tree there :validate t :if-does-not-exist :ignore))

(asdf:initialize-source-registry
 `(:source-registry
   (:tree ,(uiop:getcwd))
   :inherit-configuration))

(ql:quickload "t" :verbose t)

Now run it.

ccl --load ./loader.lisp --batch
[...]
To load "t":
  Load 1 ASDF system:
    t
; Loading "t"
> Error of type SIMPLE-ERROR: No MAKE-LOAD-FORM method is defined for #<QURI.URI:URI />
> While executing: CCL::NO-MAKE-LOAD-FORM-FOR, in process listener(1).
[...]
Version 1.12.1 (v1.12.1) LinuxX8664

I believe this is a typically missing make-load-form, and in the case of quri:uri, I see no reason to not include it.

I believe the following is a shorter recipe. Create this file:

(defvar root-uri #.(quri:uri "/")
  "Root path URL.")

then compile it (with compile-file or C-c C-k) and the complaint about the missing make-load-form should be raised, on any compiler.

@ralph-schleicher Does #83 fix it for you?

Fine for me, thank you.