1

I know that I can say (asdf:operate 'asdf:load-op <some-system>) where <some-system> is a string which names a system, and there must be a file named <some-system>.asd in a directory known to ASDF, from which the system definition is loaded. So far, so good.

I am hoping to find a way to say something similar where <some-system> is an S-expression which is the system definition, i.e. it is (defsystem "foo" ...) which has been read in or constructed by some other means.

I guess it must be possible, since at some point ASDF must read the .asd file and then act on the resulting definition, but I haven't been able to puzzle it out. I am hoping someone can point me in the right direction.

Robert Dodier
  • 16,905
  • 2
  • 31
  • 48

1 Answers1

0

Answering my own question, I was able to get it to work thanks to the hint from Rainer J.

asdf:defsystem is a macro which constructs a doodad of type ASDF/SYSTEM:SYSTEM. Then asdf:operate will take that as its argument instead of a string which names the system.

Here is a trivial example. I am working with SBCL 2.1.6 on an ancient Ubuntu system. The ASDF version is 3.3.something to judge by *FEATURES*.

In the current working directory, there is a file named bar.lisp which contains just

(defparameter baz 1234)
(format t "HELLO FROM BAR; BAZ = ~d~%" baz)

Now in the SBCL session I say:

* (require 'asdf)
NIL
* (asdf:defsystem "foo" :pathname #.*default-pathname-defaults* :components ((:file "bar")))
#<ASDF/SYSTEM:SYSTEM "foo">

to construct the system foo. To tell ASDF to look in the current working directory, the sharp-dot is necessary because otherwise *DEFAULT-PATHNAME-DEFAULTS* isn't evaluated (since ASDF:DEFSYSTEM is a macro). There are other ways to wedge the value in there (aside from just a string or pathname -- a pathname is maybe not supposed to work but I find it does), but anyway sharp-dot works.

With that system instance in hand, I can load it:

* (asdf:operate 'asdf:load-op *)
; compiling file "/home/robert/tmp/bar.lisp" (written 27 DEC 2022 10:10:04 AM):
; processing (DEFPARAMETER BAZ ...)
; processing (FORMAT T ...)

; wrote /home/robert/.cache/common-lisp/sbcl-2.1.6-linux-x86/home/robert/tmp/bar-tmp7LQ0A0VI.fasl
; compilation finished in 0:00:00.004
HELLO FROM BAR; BAZ = 1234
#<ASDF/LISP-ACTION:LOAD-OP >
#<ASDF/PLAN:SEQUENTIAL-PLAN {9A633C49}>

and verify the variable BAZ is there:

* baz
1234

Ta-da!!

Robert Dodier
  • 16,905
  • 2
  • 31
  • 48