Skip to content

Instantly share code, notes, and snippets.

@dnaeon
Created January 16, 2020 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnaeon/5018d1e5ebbc22a59f67a8e1b6a6ef35 to your computer and use it in GitHub Desktop.
Save dnaeon/5018d1e5ebbc22a59f67a8e1b6a6ef35 to your computer and use it in GitHub Desktop.
CL packages
;;;; Path: ~/quicklisp/local-projects/foo/src/bar.lisp
(defpackage foo.bar
(:nicknames :foo.bar)
(:use :cl)
(:export :my-function))
(in-package :foo.bar)
;; :arrows is not imported, but I can still access it
;;
;; What is the point of :USE'ing or :IMPORT-FROM it in that case???
(defun my-function ()
(arrows:-> 2 (+ 40)))
;;;;
;;;; Consider that we have the following system in our Quicklisp's local-project (e.g. ~/quicklisp/local-projects)
;;;;
;;;; Path: ~/quicklisp/local-projects/foo/foo.asd
(defpackage :foo-system
(:use :cl :asdf))
(in-package :foo-system)
(defsystem :foo
:name "foo"
:description "Foo system"
:version "0.1.0"
:author "John Doe <john.doe@example.org>"
:maintainer "John Doe <john.doe@example.org>"
:licence "BSD 2-Clause"
:long-description ""
:homepage ""
:bug-tracker ""
:source-control ""
:long-name ""
:depends-on (:arrows)
:components ((:module "src"
:components
((:file "bar")))))
CL-USER> (ql:register-local-projects)
NIL
CL-USER> (ql:quickload :foo)
To load "foo":
Load 1 ASDF system:
foo
; Loading "foo"
To load "arrows":
Load 1 ASDF system:
asdf
Install 1 Quicklisp release:
arrows
; Fetching #<URL "http://beta.quicklisp.org/archive/arrows/2018-10-18/arrows-20181018-git.tgz">
; 4.95KB
==================================================
5,067 bytes in 0.00 seconds (4948.24KB/sec)
; Loading "arrows"
[package arrows].
To load "foo":
Load 1 ASDF system:
foo
; Loading "foo"
[package foo.bar]
(:FOO)
CL-USER> (foo.bar:my-function)
42
CL-USER>
@dnaeon
Copy link
Author

dnaeon commented Jan 16, 2020

When ql:quickload'ing the :foo system the :arrows dependency is being downloaded, built and loaded, which in turn makes it readily available for our foo.bar package to use without having to :use or :import-from it.

What is the point of of using :use or :import-from within the defpackage definition, if the dependencies are already loaded and available?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment