Re: organizing lisp code
- From: liyer.vijay@xxxxxxxxx
- Date: 30 May 2006 19:48:00 -0700
Pascal Costanza wrote:
liyer.vijay@xxxxxxxxx wrote:
Hi
Is there any convention for organizing lisp code into different files?
No, there is no convention that you can mechanically follow.
I'm most used to Java where every class goes into it's own files (with
a few exceptions, of course) but that seems overkill in lisp where a
defclass would probably be just a few lines at most.
In Java, a file can also contain several classes, even without inner
classes. It indeed makes sense to put helper classes together with the
classes they help in the same file even in Java.
True but typically each java file has one class and the
inner classes or other classes in that file are used as
helpers for the main class (after which the file itself is
named). Basically, the only `symbols' that are exported are
the class after which the file is named and it's public
symbols and other classes are not. This is not the case in
Lisp.
So the guideline in Common Lisp is this: Think about what code belongs
together because of what it does, not in what construct it is expressed.
As an analogy: In a book, you also don't start a new chapter for each
sentence, and there is also no convention how to organize your text into
chapters.
I don't understand this analogy right now. But I shall not
question it either. You obviously know what you are talking
about. Hopefully someday I will understand the Lisp world
better and come back to you with my opinion of this.
In another post, it was discussed that the defgeneric's be in defined
on their own since in CLOS methods don't belong to the classes
themselved.
Again: Organize the code according to its meaning, not its structural
properties. Sometimes it is better to define methods close to the
classes on which they are specialized, and sometimes its better to
collect them all together.
All right. I am not used to the Lisp way yet. It is
unusual to be allowed to do just about anything in the
language. Right from starting variables with numbers (I
don't use this but it is cool nonetheless :-) to variables
using the same name as a function to complete freedom in
CLOS and the like. And then you have macros of course.
Recall what you use the Visitor pattern for in languages like Java: You
use the Visitor pattern so that you can group functionality together.
Whenever you would use the Visitor pattern, just group all the methods
for a generic function together (and forget about double dispatch and
all the ugly details of Visitors ;).
Actually I've never used the Visitor pattern in Java. I've
seen a toy C compiler written in Python use it and I've seen
Peter Seibel's speech at Google. Scary.
Thanks for the help!
Cheers
Vijay Lakshminarayanan
.
- Follow-Ups:
- Re: organizing lisp code
- From: Pascal Costanza
- Re: organizing lisp code
- References:
- organizing lisp code
- From: liyer . vijay
- Re: organizing lisp code
- From: Pascal Costanza
- organizing lisp code
- Prev by Date: Re: organizing lisp code
- Next by Date: Re: Just can't hear enough about Cells?
- Previous by thread: Re: organizing lisp code
- Next by thread: Re: organizing lisp code
- Index(es):
Relevant Pages
|