Loading code from PCL with quicklisp

Discussion of Common Lisp
Post Reply
Beltxarga
Posts: 5
Joined: Fri Apr 04, 2014 7:03 am
Location: France

Loading code from PCL with quicklisp

Post by Beltxarga » Fri Apr 04, 2014 7:29 am

Hello everybody,

As a beginner with Common Lisp (and programming), I am having trouble understanding what I think are basic concepts of quicklisp/ASDF. I am trying to load some code from Practical Common Lisp (chapter 3, "simple database") in my environment. I use Emacs + SLIME + SBCL + quicklisp. I copied the files from chapter 3 ('chapter-3.asd', 'packages.lisp', 'simple-database.asd' and 'simple-database.lisp') in my quicklisp local-projects directory. At the SLIME REPL, I type this:

Code: Select all

(ql:quickload :simple-database)
And I get the following output:

Code: Select all

 To load "simple-database":
  Load 1 ASDF system:
    simple-database
; Loading "simple-database"

(:SIMPLE-DATABASE)
After doing this, I thought I could have access to the functions from simple-database.lisp at the REPL, but the REPL tells me that all the functions I try from simple-database.lisp are undefined. I also tried this, as written in the README file from PCL:

Code: Select all

(asdf:oos 'asdf:load-op :simple-database)
Am I missing some fundamental concept about quicklisp or ASDF? Should I be able to have access to the functions from simple-database.lisp file after doing this?

Thank you very much for your help,

Beltxarga

edgar-rft
Posts: 226
Joined: Fri Aug 06, 2010 6:34 am
Location: Germany

Re: Loading code from PCL with quicklisp

Post by edgar-rft » Fri Apr 04, 2014 4:22 pm

Quoting your text from above (to make it easier to understand), here is what I did to find out what the problem is:

I copied the files from chapter 3 ('chapter-3.asd', 'packages.lisp', 'simple-database.asd' and 'simple-database.lisp') in my quicklisp local-projects directory.

Then at the SLIME REPL:

Code: Select all

CL-USER> (ql:quickload :simple-database)
To load "simple-database":
  Load 1 ASDF system:
    simple-database
; Loading "simple-database"
[package com.gigamonkeys.simple-db]
(:SIMPLE-DATABASE)
CL-USER>
To use the functions from the com.gigamonkeys.simple-db package I need to change from the cl-user package to the com.gigamonkeys.simple-db package by typing:

Code: Select all

CL-USER> (in-package :com.gigamonkeys.simple-db)
#<PACKAGE "COM.GIGAMONKEYS.SIMPLE-DB">
SIMPLE-DB>
The SLIME prompt changes from CL-USER> to SIMPLE-DB>.

Now I can use the database functions from PCL:

Code: Select all

SIMPLE-DB> (make-cd "Roses" "Kathy Mattea" 7 t)
(:TITLE "Roses" :ARTIST "Kathy Mattea" :RATING 7 :RIPPED T)
SIMPLE-DB> 
To change back to the cl-user package I type:

Code: Select all

SIMPLE-DB> (in-package :cl-user)
#<PACKAGE "COMMON-LISP-USER">
CL-USER>
Packages are explained later in PCL Chapter 21, Programming in the Large: Packages and Symbols (don't read this now because it's advanced stuff).

The code in the book shows the CL-USER> prompt because all functions are defined interactively at the CL-USER> prompt (and therefore are interned in the cl-user package), but if you use the example code you need to change to te respective package that is printed after quicklisp has loaded the files.

Have fun with Common Lisp!

- edgar

Beltxarga
Posts: 5
Joined: Fri Apr 04, 2014 7:03 am
Location: France

Re: Loading code from PCL with quicklisp

Post by Beltxarga » Fri Apr 04, 2014 5:20 pm

Thank you very much Edgar! It works now. I love to do everything in Emacs, so I was really impatient to build and use a perfect Common Lisp environment in it. Maybe I should have waited a little bit to avoid the 'black box' effect - as a matter of fact, I still don't really understand what (ql:quickload :simple-database) really does. I guess I will understand it later when notions like packages are clear in my mind.
edgar-rft wrote:Have fun with Common Lisp!
I'm having a lot of fun already :D Chapter 3 is intense!

Beltxarga

edgar-rft
Posts: 226
Joined: Fri Aug 06, 2010 6:34 am
Location: Germany

Re: Loading code from PCL with quicklisp

Post by edgar-rft » Fri Apr 04, 2014 7:27 pm

In case you get completely stuck some day, there is another free book for absolute Lisp beginners:
That's the book where I had learned Lisp programming from (for just the simple reason that Practical Common Lisp didn't exist at that time). It has less practical examples, but it explains everything from the very basics.

The good news is: If you have managed to get Emacs, SLIME and Common Lisp running, the worst part is already done.

- edgar

Beltxarga
Posts: 5
Joined: Fri Apr 04, 2014 7:03 am
Location: France

Re: Loading code from PCL with quicklisp

Post by Beltxarga » Sat Apr 05, 2014 7:11 am

'Common Lisp: A Gentle Introduction To Symbolic Computation' is indeed the perfect companion to 'Practical Common Lisp' in my beginner's opinion, and luckily these are the two physical books I bought for learning Common Lisp ;). I think PCL alone + Internet would be enough for a motivated beginner at programming, but reading Touretzky's book from cover to cover (especially doing the exercises!) may be the best thing to do before diving into PCL. I started by reading the first ten chapters of it before switching to Seibel's book. Yes, I was impatient in the end to see the practical side, and Seibel's book is more aesthetically appealing :D But reading Touretzky's was definitely very useful, and I'm going to finish it soon.

I have other PDF books for later: 'Land of Lisp', 'Let Over Lambda', Paul Graham's 'On Lisp' and the very intimidating 'Paradigms of Artificial Intelligence Programming'. I will probably have a look at 'Land of Lisp' first.

Post Reply