Re: package frenzy



Joris Bleys wrote:
Hello all!

I'm experiencing some problems using packages in Lisp and I'm wondering what your opinions are about the packages-facility in Lisp. I've been hearing around and most of my comrades suggest not to use packages. I'd like to use them to avoid nasty things like name-clashes (that's what they're for, right?). Is there any guide on how packages should be used?

No, you absolutely should use packages. Programming in the CL-USER package means your code cannot be integrated with others who do the same, and is possibly nonportable anyway since implementations can stick any symbols they want in that package.

I typically make the packages fairly large, and put their definitions
off in their own files, but this is style.

It's a good idea to avoid using the :: package prefixes when possible.
That's a sign that someone is cheating and going behind the back
of a package's public interface.


Let's say I have some package :exporting-package, which has two functions: ep-internal-fn and ep-external-fn. The ep-internal-fn gets a string as argument and returns a symbol using (read-line str NIL NIL). The ep-external-fn uses eq to compare the result of ep-internal-fn with a pre-programmed symbol 'TEST. The ep-external-fn is exported.

Now another package is defined :importing-package which uses the :exporting-package (use-package). When ep-external-fn is called, the equality is always false. This happens because the result of ep-external-fn is a symbol in the package :importing-package, whereas the 'TEST symbol is defined in the :exporting-package.

That symbol was part of the API of the exported function, so it itself should have been exported also. Or, you could have used a keyword symbol.

(Also be careful when calling READ-LINE that you've bound *PACKAGE*
appropriately.)

	Paul
.



Relevant Pages

  • Re: Survey: Do you use the "2" in Lisp-2?
    ... Lisp1 and Lisp2, which I created, are not widely used because I ... This is probably a useful criticism in a few cases but I don't think ... such as Common Lisp model or Scheme model to describe it. ... You have also blurred the distinction between modules and packages. ...
    (comp.lang.lisp)
  • Re: Windows Common LISP
    ... Windows is my platform ... underserved when it comes to Common LISP and somewhat newbie- ... I imagine multiple packages or a single packages but with choices (the ... , starting up the IDE ...
    (comp.lang.lisp)
  • Re: Why Lisp is too hard for me to use
    ... Lisps and several libraries. ... so it needs implementation support. ... The current strong support for Lisp ... > This consists of simple .tar.gz packages, ...
    (comp.lang.lisp)
  • Re: CLOS usage patterns?
    ... Nick Lacey writes: ... In Lisp the smallest things these ... Maybe your problem is that you are not creating enough packages, ... > doesn't take the public/private distinction as seriously as Java. ...
    (comp.lang.lisp)
  • Re: A problem statement (and a proposed solution)
    ... that there is progress in the language. ... Lisp in a box does not exist. ... handful packages included. ... Lisp is so special that you don't need to use libraries written by others. ...
    (comp.lang.lisp)