I'm looking at the cl-modlisp files to see how ASDF packaging is done,
particularly for SBCL. In order to avoid cargo cult programming, I
have a question about this:
(in-package #:cl-user)
(defpackage #:modlisp
(:nicknames #:ml)
(:use #:cl #:kmrcl)
Why is the # used? I didn't see mention of it in the CLHS for either
in-package or defpackage.
I've actually seen a few other cases of #-something that I don't get.
I know about #' as a reader macro for (function ...) and #(a b c) for
arrays. I've seen #+ and #- but I don't know what they are for. Is
there a listing and description of these in one place?
I'm tiring of reading Lisp books as tutorials. I've decided that I
should be reading Lisp code instead and looking things up in CLHS or
asking here if I can't find out from CLHS or CLtL2. I want to hack
Lisp, not read about it if you get my meaning.
--
I wouldn't mind the rat race so much if it wasn't for all the damn cats.
First #:name means uninterned symbol name.
It is not neccesary but helps if you have nested packages.
'#+ test expression' runs expression if test is t used tha same way #ifdef
is used in C
'#- test expression' is the same except it skips the expression if test is
t.
All this and more is described in section 2.4.8 in the ANSII Hyperspec.
(You might want to read all of chaper 2 on Syntax. You can look up
functions as you need them
but not syntax elements so you end up memorizing the 'highlights' here.)
P� Sun, 18 Apr 2004 20:55:30 GMT, skrev David Steuber
<·····@david-steuber.com>:
> I'm looking at the cl-modlisp files to see how ASDF packaging is done,
> particularly for SBCL. In order to avoid cargo cult programming, I
> have a question about this:
>
> (in-package #:cl-user)
>
> (defpackage #:modlisp
> (:nicknames #:ml)
> (:use #:cl #:kmrcl)
>
> Why is the # used? I didn't see mention of it in the CLHS for either
> in-package or defpackage.
>
> I've actually seen a few other cases of #-something that I don't get.
> I know about #' as a reader macro for (function ...) and #(a b c) for
> arrays. I've seen #+ and #- but I don't know what they are for. Is
> there a listing and description of these in one place?
>
> I'm tiring of reading Lisp books as tutorials. I've decided that I
> should be reading Lisp code instead and looking things up in CLHS or
> asking here if I can't find out from CLHS or CLtL2. I want to hack
> Lisp, not read about it if you get my meaning.
>
--
Sender med M2, Operas revolusjonerende e-postprogram: http://www.opera.com/
John Thingstad <··············@chello.no> writes:
> All this and more is described in section 2.4.8 in the ANSII Hyperspec.
> (You might want to read all of chaper 2 on Syntax. You can look up
> functions as you need them
> but not syntax elements so you end up memorizing the 'highlights' here.)
Thanks, all.
Now would it be a crime to develop an ASDF package for SBCL with
:sb-thread and :sb-futex? I've found myself narrowing down the Lisps
I want to work with because there are inevitable implementation
differences on top of a huge ANSI spec. Right now, SBCL has my
attention on Linux and OpenMCL on OS X.
I'm also feeling rather behind where I should be. KMR's cl-modlisp is
not a large package (about 370 lines in .lisp files according to wc
-l). That little bit of code already has features beyond my
understanding. It uses CLOS for one thing (for the Apache listener).
I've also seen use of backquoted forms in defun's. I thought
backquoting was for macros (another topic I have not picked up yet).
It took me a few moments to even remember that ,foo ment evaluate foo
in a ` form.
--
I wouldn't mind the rat race so much if it wasn't for all the damn cats.
David Steuber wrote:
> I've also seen use of backquoted forms in defun's. I thought
> backquoting was for macros (another topic I have not picked up yet).
Macros are just the killer app for backquote, because in them you want
to return a long list of mostly literals (the template code) with macro
arguments spliced in as runtime values.
here is a non-macro version from cello:
(let ((styles `((Object . ,gl_object_linear)
(Eye . ,gl_eye_linear)
(Sphere . ,gl_sphere_map))))
I just did not like the idea of the alternative:
(let ((styles (list (cons 'object gl_object_linear)...etc
kt
--
Home? http://tilton-technology.com
Cells? http://www.common-lisp.net/project/cells/
Cello? http://www.common-lisp.net/project/cello/
Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film
Your Project Here! http://alu.cliki.net/Industry%20Application
John Thingstad <··············@chello.no> wrote:
+---------------
| '#+ test expression' runs expression if test is t used
| tha same way #ifdef is used in C
+---------------
Uh... This is somewhat misleading, especially since the OP is an
acknowledged newbie. First, there's no "running" implied at all --
this is purely a READ-time conditional, and applies to *any* READ,
not just ones which result in code, e.g., in CMUCL:
> (read)
(a b #+cmu c d e #-cmu f g) ;I typed this
(A B C D E G)
>
[I have used this occasionally to conditionalize data files built of
s-exprs.]
Second, when you say "if test is t", well, not really. That is, a feature
test is not an normal Lisp expression which is evaluated for a boolean
result using the ordinary rules for Lisp evaluation, as the term "test"
might ordinarily imply. Rather, a "test" here is a special form called
a "feature expression", which consists *only* of symbols (naming items
on the features list) and a few combining operators (AND, OR, & NOT).
A feature expression consisting of just a symbol "succeeds" or "fails"
depending on whether the feature named by the symbol is an element of
the list held by the variable *FEATURES* at the time the read occurs.
A complex feature expression succeeds or fails based on the obvious
AND/OR/NOT combination of the named feature(s):
> (read)
(a b #+cmu c1 #+allegro c2 d e #+(not (or cmu allegro)) f g)
(A B C1 D E G)
>
which could also be written as this:
> (read)
(a b #+cmu c1 #+allegro c2 d e #-(or cmu allegro) f g)
(A B C1 D E G)
>
The features list can be altered during the life of a given Lisp image,
e.g., by loading some library that modifies *FEATURES*, so some care must
be taken when using them.
> #+foo "foo" #-foo "bar"
"bar"
> (push :foo *features*)
(:FOO :ASDF :PCL-STRUCTURES :PORTABLE-COMMONLOOPS :PYTHON :PCL
:ELF :FREEBSD4 :FREEBSD :BSD :UNIX :LINKAGE-TABLE :GENCGC :MP
:PENTIUM :I486 :X86 :IEEE-FLOATING-POINT :ANSI-CL :COMMON-LISP
:COMMON :NEW-COMPILER :HASH-NEW :COMPLEX-FP-VOPS
:CONSERVATIVE-FLOAT-TYPE :RANDOM-MT19937 :RELATIVE-PACKAGE-NAMES
:CMU18E :CMU18 :CMU)
> #+foo "foo" #-foo "not-foo"
"foo"
>
Note that the feature test itself (though not the expressions which
follows it) is read with *PACKAGE* temporarily bound to KEYWORD, so
the elements of the features list should be keywords, too. [Yes, you
can hack around this, but it's not recommended for normal use.]
Finally, as with normal AND & OR special operators, the AND & OR
feature expression combiners succeed or fail (respectively) when
given the empty list, that is, #+(and) always succeeds and #+(or)
always fails. Conversely, #-(and) always fails and #-(or) always
succeeds.
You will see code that uses #+nil to "comment out" a complex s-expr.
There was a long thread here in c.l.lisp some time back which discussed
why this is a bad idea, and suggesting using #-(and) for this instead.
I like and use this latter form, since the normal connotations of + and -
are preserved: #+(and) always reads the following expression, and #-(and)
always ignores it.
-Rob
-----
Rob Warnock <····@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607
David Steuber <·····@david-steuber.com> writes:
> I'm looking at the cl-modlisp files to see how ASDF packaging is done,
> particularly for SBCL. In order to avoid cargo cult programming, I
> have a question about this:
>
> (in-package #:cl-user)
>
> (defpackage #:modlisp
> (:nicknames #:ml)
> (:use #:cl #:kmrcl)
>
> Why is the # used? I didn't see mention of it in the CLHS for either
> in-package or defpackage.
>
Well, in my humble understanding
(in-package #:foo)
(in-package :foo)
(in-package 'foo)
(in-package "FOO")
have roughly the same effect. When given a symbol, in-package uses its
print-name, and the reason of using #:foo is that simbol is uninterned.
Less memory used, less namespace pollution.
Kent Pitman had posted some time ago a even trickier way of setting the
packages names which used strings, which only existed at compile time.
But he was just kidding
> I've actually seen a few other cases of #-something that I don't get.
> I know about #' as a reader macro for (function ...) and #(a b c) for
> arrays. I've seen #+ and #- but I don't know what they are for. Is
> there a listing and description of these in one place?
>
#+, #- == condititional evaluation. (list #+allegro 0 #-allegro 1) will
eval to (0) under acl and to (1) under cmucl, sbcl, etc...
> I'm tiring of reading Lisp books as tutorials. I've decided that I
> should be reading Lisp code instead and looking things up in CLHS or
> asking here if I can't find out from CLHS or CLtL2. I want to hack
> Lisp, not read about it if you get my meaning.
>
> --
> I wouldn't mind the rat race so much if it wasn't for all the damn cats.
---
~rv "Lisp is a strange attractor" -- Erik Naggum on cll.
On 18 Apr 2004 23:50:36 +0200, Vasile Rotaru <······@seznam.cz> wrote:
> Well, in my humble understanding
>
> (in-package #:foo)
> (in-package :foo)
> (in-package 'foo)
> (in-package "FOO")
>
> have roughly the same effect.
With the small exception that the last form won't work in "modern"
AllegroCL images. Some people think that this is a good thing because
those modern images aren't ANSI-compliant anyway but YMMV. I
personally prefer not to use
(in-package "FOO")
in order not to deliberately break things.
Cheers,
Edi.
David Steuber <·····@david-steuber.com> wrote:
> (in-package #:cl-user)
> (defpackage #:modlisp
> (:nicknames #:ml)
> (:use #:cl #:kmrcl)
> Why is the # used? I didn't see mention of it in the CLHS for either
> in-package or defpackage.
It's considered good form to not to litter packages not specific
to your application/library with random symbols, hence DEFPACKAGE
forms often use either
#:uninterned-symbols (symbols without a package)
"STRINGS"
:keywords
To nitpick, I personally prefer keywords for package names
and nicknames, and uninterned symbols for export list,
shadow, etc.
Why? Because some systems (eg. linedit) provide symbol completion
on keywords, so having package names interned in the keyword
package is both convenient and doesn't still fill the keyword
package with great clutter -- but adding names of other symbols
there has no benefits, and is inconvenient to those using symbol
completion.
Otoh, strings do just as fine for export lists, etc. as uninterned
symbols. It's just a matter of taste.
> I've actually seen a few other cases of #-something that I don't get.
> I know about #' as a reader macro for (function ...) and #(a b c) for
> arrays. I've seen #+ and #- but I don't know what they are for. Is
> there a listing and description of these in one place?
#- and #+ are reader macros that provide conditionalization.
When the reader processes the following
#-foo (do-stuff-to-fix-lack-of-foo)
the (do-stuff...) is ignored if :FOO is in *FEATURES*,
but read normally otherwise.
#+ is just the opposite:
#+bar (fix-bar)
Means that the reader will ignore the (fix-bar) unless :BAR is
in *FEATURES*.
Excessive reader conditionalization is not generally a good idea.
Cheers,
-- Nikodemus
David Steuber wrote:
> I'm looking at the cl-modlisp files to see how ASDF packaging is done,
> particularly for SBCL. In order to avoid cargo cult programming, I
> have a question about this:
>
> (in-package #:cl-user)
>
> (defpackage #:modlisp
> (:nicknames #:ml)
> (:use #:cl #:kmrcl)
>
> Why is the # used? I didn't see mention of it in the CLHS for either
> in-package or defpackage.
that solves a real problem, which I myself spent quite a few minutes
sorting out when into it I ran.
#:this is an uninterned symbol. In the above example, you are avoiding
adding symbols inadvertently to cl-user, which would happen when the
defpackage form gets read.
Another way to do this is to use "this", which defpackage also accepts.
kt
--
Home? http://tilton-technology.com
Cells? http://www.common-lisp.net/project/cells/
Cello? http://www.common-lisp.net/project/cello/
Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film
Your Project Here! http://alu.cliki.net/Industry%20Application
David Steuber <·····@david-steuber.com> writes:
> I've actually seen a few other cases of #-something that I don't
> get. [...] Is there a listing and description of these in one
> place?
CLHS 2.4.8 (and subsections) describes "all reader macros associated
with the dispatching macro character #":
http://clhs.lisp.se/Body/02_dh.htm
--
Lars Brinkhoff, Services for Unix, Linux, GCC, HTTP
Brinkhoff Consulting http://www.brinkhoff.se/