PDA

View Full Version : [SOLVED] (defpackage :help-madness)



Lau_of_DK
May 31st, 2008, 07:59 PM
Gents,


I wrote a little library in Lisp, by which you can use every data type as a lazy stream, greatly inspired by the SICP videos. Anyway, it works great and I'm very happy with it. So happy in fact that I want to use it in one of my other projects - but how do I do this?

I tried prefixing my lib with



(defpackage ":COM.BESTINCLASS.STREAMS"
(:use "COMMON-LISP")
(:export :the-empty-strem
:cons-streams
:head
:tail
:empty-stream?
:map-stream
:filter-stream
:append-streams
:enum-interval
:flat-map
:flatten
:accumulate
:nth-stream))


And that compiles like it should. Then afterwards I load up my other project, and start off with



(use-package :com.bestinclass.streams)
or
(in-package :com.bestinclass.streams)


No matter what - I get a "function undefined" when I try to execute them with unqualified names. (I think it was the same with qualified names).

Somebody sharp with packages that can help me out?


/Lau

Lau_of_DK
May 31st, 2008, 09:38 PM
Come on folks,

Somebody's gotta have a take on this? :)


/Lau

Jessehk
May 31st, 2008, 10:00 PM
Look into ASDF for help with conditional compilation and requiring external libraries.

Lau_of_DK
May 31st, 2008, 10:02 PM
Look into ASDF for help with conditional compilation and requiring external libraries.

This is not ASDF related.

/Lau

Alasdair
June 1st, 2008, 12:49 AM
The problem is on the following line:

(defpackage ":COM.BESTINCLASS.STREAMS"

Why do you have the :colon at the start of the (string) package name? That's what's breaking it. The colon in lisp is a reader macro, much like a the backtick (`) or the comma (,). Any symbol preceded with a colon is interned into a special keyword package. Essentially what is happening is this: lisp thinks the package is called ":COM.BESTINCLASS.STREAMS", but when you try to refer to it as :com.bestinclass.streams, the colon is interpreted as the keyword reader macro, and lisp finds the name of the com.bestinclass.streams symbol in the keyword package, which is of course "COM.BESTINCLASS.STREAMS" without the colon.

I would recommed using one notation consistently throughout your program for packages, either use :keywords "STRINGS" or #:uninterned-symbols, but don't mix n' match.

See this pdf (http://www.flownet.com/gat/packages.pdf) for everything you could ever want to know about packages (but were afraid to ask :)).

Lau_of_DK
June 1st, 2008, 12:59 AM
Thanks for posting alasdair.


There were a few issues. Firstly, like you said, I should stick to keywords, which I did. Then secondly, I wasnt aware that you had to specify (in-package) after defining it, but of course you do.

And then thats basically it, its working now.

Thanks,
Lau