Global namespace (was Re: python libs v lisp coolness?
Christophe Rhodes
csr21 at cam.ac.uk
Wed Oct 29 11:28:22 EST 2003
Ville Vainio <ville.spammehardvainio at spamtut.fi> writes:
> Paolo Amoroso <amoroso at mclink.it> writes:
>
>> The lack of Lisp libraries is being addressed.
>
> Are they also going to address the lack of modules? The way I've seen
> Lisp used, everything is dumped into a global namespace (even
> "methods" in CLOS). I shudder at the thought of using Python where all
> the names from various modules would be in the global namespace.
>
> in Python you can do:
>
> import os
>
> files = os.listdir("/root")
Knowing no python, I believe the Common Lisp equivalent of this is
(cl:defpackage "MY-APP" (:use "CL"))
(cl:in-package "MY-APP")
(os:listdir "/root")
Optionally, if one wishes to import an interface wholesale and use it
without qualification, one may USE-PACKAGE a package, for example:
(cl:defpackage ("MY-OTHER-APP") (:use "CL" "OS"))
(cl:in-package "MY-OTHER-APP")
(listdir "/root")
[ this is written for maximum paranoia; usually you wouldn't see the
cl: prefixes on defpackage and in-package. ]
Ancient code is typically less careful about stomping over the global
namespace; if you see (in-package "CL-USER") anywhere, reeducate the
maintainer of the code :-)
Christophe
--
http://www-jcsu.jesus.cam.ac.uk/~csr21/ +44 1223 510 299/+44 7729 383 757
(set-pprint-dispatch 'number (lambda (s o) (declare (special b)) (format s b)))
(defvar b "~&Just another Lisp hacker~%") (pprint #36rJesusCollegeCambridge)
More information about the Python-list
mailing list