2

I use ADSF to organise my projects.

(asdf:defsystem :sender
  :version "0.1.4"
  :serial t
  :depends-on (:cl-json :dexador :clsql :clsql-sqlite3)
  :components ((:file "packages")
               (:file "validation")
               (:file "sender")))

But when I open a new repl (slime, emacs), I have to go to the packages.lisp file and evaluate the form before I can change the repl to that package with (in-package :sender).

Is there a way to make the slime repl remember my packages?

My current thinking is that I need to "run" adsf to load all my files. If so, how?

UPDATE:

Actually, I need to compile all the files manually before I can actively use them in the repl. I believe I am using asdf incorrectly.

Vinn
  • 1,030
  • 5
  • 13

2 Answers2

2

From a .asd system definition, the steps would be:

  • compile the .asd file, so that you Lisp image knows about the system
    • C-c C-k or programmatically: (asdf:load-asd "system").
  • LOAD it somehow: (ql:quickload "system") to install dependencies
    • or (asdf:load-system "system"), but it will fail if your project has unknown dependencies, Quicklisp would download them.
    • avoid using cl:load for asdf systems, load-asd / load-system will do more complex stuff.
  • use it on the REPL. The package that was defined in a packages.lisp file should be available, because this file was declared in the .asd.

You can add stuff to your ~/.sbclrc (or similar for other implementations). Here I tell ASDF where a project lives, so I can quickload it without manually compiling the .asd before:

(pushnew "/home/vince/projets/ciel/" asdf:*central-registry* :test #'equal)

This is an "old" style not encouraged anymore by the ASDF documentation.

Or simply create a symlink for your project to ~/quicklisp/local-projects/ or ~/common-lisp/.

I wouldn't "load-system" my project in the init file, because that's a side effect that would show sometimes when I don't want it (like building an image: if that involves reading my init file, I'd have an unwanted system in it).

Saving a core image with a ton of dependencies is cool. Use it with sbcl --core …. The advantage is that it starts up instantly in the REPL, when loading all projects and dependencies would take a few seconds.

Ehvince
  • 17,274
  • 7
  • 58
  • 79
1

Pointers

ASDF

ASDF cookbook

ASDF manual

ASDF best practices

ASDF Build System explained

Overview

A system is an object which describes a library (or an application) which consists of: a name, a version, a list of files and subsystems, and a list of other systems it depends on. There is more.

If you want to have Lisp know a certain system, then we need to execute its defsystem form either manually or find it automatically. That ONLY makes the system definition known.

If you want to load the system's files, then you need to LOAD the SYSTEM. If you want to compile the system's files files, the you need to COMPILE the system.

So, if you want to use a package (which is a namespace), then you need to run the DEFPACKAGE form. If that form is describe in a file which is component of a system, then you need to load that system.

  • ASDF : a popular build system for Common Lisp

  • system -> library, application. It is a bunch of files and dependencies.

  • system definition -> not the system itself, but a description of it. Use DEFSYSTEM to describe a system

  • system operations -> like load-system, compile-system and others.

  • system registry -> Typically we want ASDF to find the systems by name. See the manual or a tutorial for ASDF.

  • lisp file -> some file we can compile or load

  • fasl file -> some compiled file we can load

  • package -> a namespace for symbols, that's actually a built-in feature for Common Lisp

  • Quicklisp -> a library manager with a selection of curated Common Lisp libraries/applications. The libraries can be loaded over the Internet. Be aware that there is little to no security when loading foreign code from the Internet.

Use a system, its components and dependencies

If you want to use a system you need to load it first. Manually or automatically.

That loading can be done automatically:

  • For example in an init-file for your Lisp you can load all systems you want/need. Alternative write a function which loads all systems you want.

  • saving an image. Some Lisps support saving an image. Thus one can load all interesting systems and then save an image. If one starts that image later, all those systems are already in memory. (side problem: getting newer versions loaded)

Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346
  • Understood. So, what do I need to add to the init file to load and compile the system automatically. I tried this `(load (compile-file "~quicklisp/local-projects/sender/sender.asd"))` with no luck – Vinn Jan 06 '23 at 09:23
  • Likely: you've loaded the system definition. Now you would need to compile and/or load the system itself. You need to understand the difference between a description of something and the thing itself. To use a system in your Lisp, you need to load it. See the options to LOAD a SYSTEM. – Rainer Joswig Jan 06 '23 at 12:15