Lisp - Defining System



Defining a System refers to collection of related files into one logical unit like a library or an application. Lisp is not having built-in support for such managment but we can use system definition tools like ASDF, Another System Definition Facility. ASDF can be used to handle definition and management of a LISP system.

Usage of ASDF to define a System

ASDF provides a structure in which we can define our LUA project as a system. We can define the dependencies, when those dependencies are to be loaded, either during compilation or during load time. An ASDF system file as .asd file generally looks like following −

Following code shows various scenarios.

my-system.asd

(defsystem my-system
   :version "0.1.0"
   :author "Admin <admin@tutorialspoint.com>"
   :license "MIT"
   :description "My First System"
   :depends-on (:some-dependency :another-dependency)
   :components ((:module "src"
      :components ((:file "main")
         (:file "utils")))
			(:file "tests")))

Where

  • defsystem my-system starts the core form defining the system. my-system is name of our LISP project. Generally it is all lowercase.

  • :version represents the version of the system.

  • :author represents the author(s) of the system.

  • :license represents the distribution license of the system.

  • :description is used to provide a short description of the system.

  • :depends-on is used to provide list of other ASDF based dependencies on which our system is dependent. Usually these libraries are available using QuickLisp.

  • :components is used to provide list of parts of the application including source files or folders containing source files.

Example Directory Structure

A typical structure for a system can be as shown below −

my-system/
|-- my-system.asd
|-- src/
|   |-- main.lisp
|   |-- utils.lisp
|-- tests.lisp

Loading ASDF Based System

Once .asd file is define, we can use ASDF functions to load system in the environment and start interactions. In Common LISP, ASDF is generally pre-loaded. In case it is not present, it can be installed using QuickLisp.

; Using Quicklisp as recommended
(ql:quickload :my-system)

or using asdf:load-system.

; Using ASDF directly, less commonly used
(asdf:load-system :my-system)

It will load all dependencies in correct order and then project will be compiled and loaded. Now we can use functions, or other code available in our system project in the current project seemlessly.

Advantages of ASDF

  • Standardization − ASDF provides a standard way to define and manage various LISP projects in a consistent manner.

  • Dependency Management − We can load required libaries easily.

  • Compilation − Automatic compilation of source files.

  • Portability − Being a standard system, code can be accessed by other projects easily.

  • Integration with Quicklisp − QuickLisp is one of the most popular Lisp library manager. An integration with QuickLISP makes it easy for developers to use ASDF seemlessly.

Advertisements