Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Beginner Question about Lisp with CL-GD

78 views
Skip to first unread message

Bruno Burke

unread,
May 18, 2013, 4:09:37 AM5/18/13
to
Hello everyone,

I'm learning to program with Lisp (Clozure CL) and have a problem with
using some "libraries".

I have downloaded cl-gd (GD-Lib for Common Lisp) with (ql:quickload
"cl-gd") and then i compiled the C-Glue-Code in the folder of cl-gd.
I can execute the tests with
(ql:quickload "cl-gd-test")
(cl-gd-test:test)
and it seems that only 3 of ~20 tests failed.

So my question is, how do I use extern libraries like cl-gd in my project?
I have this Lisp Program(create a 40x40 graphic with colored background):
(ql:quickload "cl-gd")
(with-image* (40 40)
(allocate-color 20 20 20)
(write-image-to-file "test.png" :compression-level 6 :if-exists :supersede))

but if i want to execute it, the Interpeter tells me, that all used
functions are undefined functions. Didn't they get defined if I load the
package with (ql:quickload "cl-gd")?

What is the right way to "include" libraries?

Thanks for your attention,

B

Marco Antoniotti

unread,
May 18, 2013, 5:51:05 AM5/18/13
to
The problem you have is that you are not qualifying the names. quicklisp is itself a "library"; not part of the language and it solves a different problem (similar to what CPAN, CRAN etc solve). In particular it does not, and rightly so, do the equivalent of an "import" (Java, Python etc) or a "use" in other languages. You have to do so explicitly.

Either you use the package qualifiers explicitly or you issue a USE-PACKAGE.

(ql:quickload "cl-gd")

(cl-gd:with-image* (40 40)
(cl-gd:allocate-color 20 20 20)
(cl-gd:write-image-to-file "test.png" :compression-level 6 :if-exists :supersede))

or

(ql:quickload "cl-gd")

(use-package "CL-GD")

(with-image* (40 40)
(allocate-color 20 20 20)
(write-image-to-file "test.png" :compression-level 6 :if-exists :supersede))

Hope it helps.

Cheers

--
MA

Pascal J. Bourguignon

unread,
May 18, 2013, 6:30:40 AM5/18/13
to
Marco Antoniotti <mar...@gmail.com> writes:

> On Saturday, May 18, 2013 10:09:37 AM UTC+2, Bruno Burke wrote:
>> I'm learning to program with Lisp (Clozure CL) and have a problem with
>> using some "libraries".
>>
> (ql:quickload "cl-gd")
>
> (use-package "CL-GD")

And notice that while it's often the case that the name of the asdf
system loaded by quickload and the name of (one of) the package(s)
defined in that system are string-equal, it's necessarily the case.

I mean, don't infer a 1-1 relationship between packages and asdf
systems.


--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.
You can take the lisper out of the lisp job, but you can't take the lisp out
of the lisper (; -- antifuchs

Bruno Burke

unread,
May 18, 2013, 10:20:57 AM5/18/13
to
Thank you for your help. It works.
The first way with explicit qualifiers works without a problem.

When I use (use-package "CL-GD") I get this error:
Using #<Package "CL-GD"> in #<Package "COMMON-LISP-USER">
would cause name conflicts with symbols already present in that package:
*DEFAULT-IMAGE* CL-GD:*DEFAULT-IMAGE*
THICKNESS CL-GD:THICKNESS

So it seems, that these symbols are already defined in my User Package?
If I use (in-package "cl-gd") it works without an error / but I think
in-package is intended to be used if i want to extend the functionality
of cl-gd // but thats not what i want, I only want to use its functions.

Thanks

B

Pascal J. Bourguignon

unread,
May 18, 2013, 10:49:09 AM5/18/13
to
Bruno Burke <bruno...@googlemail.com> writes:

> When I use (use-package "CL-GD") I get this error:
> Using #<Package "CL-GD"> in #<Package "COMMON-LISP-USER">
> would cause name conflicts with symbols already present in that package:
> *DEFAULT-IMAGE* CL-GD:*DEFAULT-IMAGE*
> THICKNESS CL-GD:THICKNESS
>
> So it seems, that these symbols are already defined in my User
> Package?

Yes, since you had your REPL read a symbol named "*DEFAULT-IMAGE*" by
typing *default-image* at it, it has interned a symbol named
"*DEFAULT-IMAGE* in the package COMMON-LISP-USER (which is the default
current package).

And now you're asking it to add to the use list of the COMMON-LISP-USER
package a package that exports a symbol with the same name!

Make up your mind!

Do you want COMMON-LISP-USER:*DEFAULT-IMAGE* or CG-GD:*DEFAULT-IMAGE*?
Which one will it be?

Do you expect the lisp system to know what you intend?
Perhaps you're expecting it to know what you will be programming next?
Perhaps you can just go home and let it do your work instead of you?


> If I use (in-package "cl-gd") it works without an error / but I think
> in-package is intended to be used if i want to extend the
> functionality of cl-gd // but thats not what i want, I only want to
> use its functions.

Interactively, when you have those conflicts, there are usually restarts
that let you choose what to do to resolve them.
If common-lisp-user:*default-image* was an error, then just select the
restart that will unintern it, and use the cl-gd package.

When you program you would use the cl-gd package in your own package, so
it should already know what symbol *default-image* names.

(defpackage "MY-PROGRAM"
(:use "COMMON-LISP" "CL-GD"))
(in-package "MY-PROGRAM")

(find-package '*default-image*) --> #<PACAKGE CL-GD>

Bruno Burke

unread,
May 18, 2013, 1:15:59 PM5/18/13
to
> Yes, since you had your REPL read a symbol named "*DEFAULT-IMAGE*" by
> typing *default-image* at it, it has interned a symbol named
> "*DEFAULT-IMAGE* in the package COMMON-LISP-USER (which is the default
> current package).

I didnt know that by using ql:quickload it loads theses symbols in the
COMMON-LISP-USER package, because by hand I never typed the symbol
*default-image*!

> And now you're asking it to add to the use list of the COMMON-LISP-USER
> package a package that exports a symbol with the same name!
>
> Make up your mind!
>
> Do you want COMMON-LISP-USER:*DEFAULT-IMAGE* or CG-GD:*DEFAULT-IMAGE*?
> Which one will it be?
>
> Do you expect the lisp system to know what you intend?
> Perhaps you're expecting it to know what you will be programming next?
> Perhaps you can just go home and let it do your work instead of you?

No;No;No -- Just as I said, I never typed or defined the symbol
*DEFAULT-IMAGE* in the REPL. I just was confused where he got that
symbol. Its not that I "want to go home and let it do all my work" and
I'm not lazy or something else - I just started to learn Lisp and don't
know everything about all the concepts of Lisp.

> Interactively, when you have those conflicts, there are usually restarts
> that let you choose what to do to resolve them.
> If common-lisp-user:*default-image* was an error, then just select the
> restart that will unintern it, and use the cl-gd package.
>
> When you program you would use the cl-gd package in your own package, so
> it should already know what symbol *default-image* names.
>
> (defpackage "MY-PROGRAM"
> (:use "COMMON-LISP" "CL-GD"))
> (in-package "MY-PROGRAM")
>
> (find-package '*default-image*) --> #<PACAKGE CL-GD>
>
>

Thanks for your help. Now I know how to start using packages

Pascal J. Bourguignon

unread,
May 18, 2013, 1:31:14 PM5/18/13
to
Bruno Burke <bruno...@googlemail.com> writes:

>> Yes, since you had your REPL read a symbol named "*DEFAULT-IMAGE*" by
>> typing *default-image* at it, it has interned a symbol named
>> "*DEFAULT-IMAGE* in the package COMMON-LISP-USER (which is the default
>> current package).
>
> I didnt know that by using ql:quickload it loads theses symbols in the
> COMMON-LISP-USER package, because by hand I never typed the symbol
> *default-image*!

It's not quickload that interns the symbols in the common-lisp-user
package, it's yourself, when you type *default-image* that orders the
lisp REPL to interns them there!


Perhaps you don't remember having typed *default-image*, but the same
applies to the other symbols you've typed in the REPL, with-image*,
allocate-color, write-image-to-file, etc.

> (ql:quickload "cl-gd")
> (with-image* (40 40)
> (allocate-color 20 20 20)
> (write-image-to-file "test.png" :compression-level 6 :if-exists :supersede))


>> And now you're asking it to add to the use list of the COMMON-LISP-USER
>> package a package that exports a symbol with the same name!
>>
>> Make up your mind!
>>
>> Do you want COMMON-LISP-USER:*DEFAULT-IMAGE* or CG-GD:*DEFAULT-IMAGE*?
>> Which one will it be?
>>
>> Do you expect the lisp system to know what you intend?
>> Perhaps you're expecting it to know what you will be programming next?
>> Perhaps you can just go home and let it do your work instead of you?
>
> No;No;No -- Just as I said, I never typed or defined the symbol
> *DEFAULT-IMAGE* in the REPL. I just was confused where he got that
> symbol. Its not that I "want to go home and let it do all my work" and
> I'm not lazy or something else - I just started to learn Lisp and
> don't know everything about all the concepts of Lisp.

Hey just joking ;-)

Bruno Burke

unread,
May 18, 2013, 4:27:26 PM5/18/13
to
Am 18.05.2013 19:31, schrieb Pascal J. Bourguignon:
> Hey just joking ;-)
>
>


First time using Newsgroups and just started programming with lisp, so
it was a bit to difficult to figure out if that was a joke/irony or just
the normal rough way of talking in Newsgroups :-)
0 new messages