-3

I am currently trying to understand how Common Lisp manages its packages and modules.

Consider this code:

(in-package :cl-user)

(ql:quickload :cl-who)
(ql:quickload :hunchentoot)
(ql:quickload :parenscript)

(defpackage :retro-games
  (:use :cl :cl-who :hunchentoot :parenscript))

(in-package :retro-games)

(defclass game ()
            ((name  :initarg  :name)
             (votes :initform 0)))

When I create a Slime buffer and then run this code in another buffer that is set to Slime mode, I see some prints in the first buffer that is *slime-repl sbcl*:

Load 1 ASDF system: cl-who ; Loading "cl-who"

To load "parenscript": Load 1 ASDF system: parenscript ; Loading "parenscript" ..

To load "hunchentoot": Load 1 ASDF system: hunchentoot ; Loading "hunchentoot" ..............

That is, there seems to be some "talking" going on between the two buffers. However, if I try to run (make-instance game("Chess")), I get an error because the CL-USER package does not know about the game class.

On the other hand if I run (in-package :retro-games) in the slime repl sbcl buffer, I am able to run (make-instance game("Chess")).

The question is how does Common Lisp organize its work with packages? On related note, what is the difference between a buffer being a slime repl sbcl and a buffer being in slime-mode?

Are the packages at all similar to Python's virtual environments? That is, where are the CL-WHO, HUNCHENTOOT and PARENSCRIPT being installed in my case? Do I have any choice over this?

Ehvince
  • 17,274
  • 7
  • 58
  • 79
MadPhysicist
  • 5,401
  • 11
  • 42
  • 107
  • did you searched for the answer on the net? there is a lot of great material on this subject (ie "Practical Common Lisp - 21. Programming in the Large: Packages and Symbols" by Peter Seibel http://www.gigamonkeys.com/book/programming-in-the-large-packages-and-symbols.html). – rsm Oct 06 '17 at 20:58
  • hi, there was no need of the python and emacs tags. – Ehvince Oct 07 '17 at 17:22
  • Quicklisp is different than Python's virtual environments. Quicklisp builds all libraries together so than they work together. See [this discussion](https://github.com/quicklisp/quicklisp-client/issues/148). If you /need/ like a venv, there is [Qlot](https://github.com/fukamachi/qlot). – Ehvince Oct 07 '17 at 17:25

1 Answers1

3

First, try (make-instance 'game :name "Chess"). Note that Common Lisp uses prefixed notation between paarenthesis. So, if want to call a function like foo("bar"), it would be (foo "bar"). If you want, you can create a function like:

(defun new-game (game-name) (make-instance 'game :name game-name))

If you are using Quicklisp, the packages me be installed at where you've installed quicklisp. If it is installed at your home folder, the packages should be at /home/user/quicklisp/dists/quicklisp/software/.

Vitor F.M.
  • 119
  • 7