From: Elvis Nguyen
Subject: How to organize a project via package
Date: 
Message-ID: <315787a3-4165-4103-b063-12455f9868f5@l2g2000vba.googlegroups.com>
Dear all,

In general, if we want to make a large program, we should have a
mechanism to organize files. That is an important point which I have
met in Common Lisp. I haven't been at how to use the package in CL.

Now, I suppose that I have the files in the project:
- main-frame.lisp
- my-project.lisp
- basic-functions.lisp

I want to define a unique package in my project, called my-project.
Currently, I am defining a package in main-frame, like this:
(defpackage :my-project
   (:use :cl :ltk))
(in-package :my-project)
.....

And my-project.lisp and basic-functions.lisp use the same package my-
project.
But, it is very uncomfortable because if I want to check some
operations in basic-functions, I must load the main-frame.lisp to
define the package my-project at I run the test (only once time when I
start sbcl)

Thus, I have a question is: How do we organize a simple program via
package? If so, you can give me a sample or tutorial.

Thanks!

Best regards,

From: Rainer Joswig
Subject: Re: How to organize a project via package
Date: 
Message-ID: <dac7ee89-6e4d-433c-81c4-0efa44d2e491@l28g2000vba.googlegroups.com>
On 13 Jul., 09:11, Elvis Nguyen <·······@gmail.com> wrote:
> Dear all,
>
> In general, if we want to make a large program, we should have a
> mechanism to organize files. That is an important point which I have
> met in Common Lisp. I haven't been at how to use the package in CL.
>
> Now, I suppose that I have the files in the project:
> - main-frame.lisp
> - my-project.lisp
> - basic-functions.lisp
>
> I want to define a unique package in my project, called my-project.
> Currently, I am defining a package in main-frame, like this:
> (defpackage :my-project
>    (:use :cl :ltk))
> (in-package :my-project)
> .....
>
> And my-project.lisp and basic-functions.lisp use the same package my-
> project.
> But, it is very uncomfortable because if I want to check some
> operations in basic-functions, I must load the main-frame.lisp to
> define the package my-project at I run the test (only once time when I
> start sbcl)
>
> Thus, I have a question is: How do we organize a simple program via
> package? If so, you can give me a sample or tutorial.
>
> Thanks!
>
> Best regards,

Often the package declarations are put in a separate file
"packages.lisp".
This makes it possible to load and maintain the package definitions
independent
from other functionality.

The software usually is loaded via some system mechanism (DEFSYSTEM).

All files are compiled/loaded with a single call to something like
(load-system :foo), where :foo is the system name.
From: Slobodan Blazeski
Subject: Re: How to organize a project via package
Date: 
Message-ID: <574dafaa-ef38-4ef5-9006-02553c053e79@l32g2000vbp.googlegroups.com>
De facto standard is to use  asdf, something like

;elvis.asd
(defsystem :elvis
    :version "0.9.3"
    :serial t
    :components
    ((:file "file1")
     (:file "file2")))


; file1.lisp
(defpackage :my-project
   (:use :cl :ltk))
(in-package :my-project)

(defun double (x) (* 2 x))

;file2.lisp

(in-package :my-project)

(defun triple (x) (* 3 x))

For the better example see some lisp library like cffi
http://common-lisp.net/project/cffi/, anaphora http://common-lisp.net/project/anaphora/
or whatever they're all packaged using asdf.

Bobi
http://www.linkedin.com/in/slobodanblazeski
From: Zach Beane
Subject: Re: How to organize a project via package
Date: 
Message-ID: <m3d485dk8s.fsf@unnamed.xach.com>
Elvis Nguyen <·······@gmail.com> writes:

> In general, if we want to make a large program, we should have a
> mechanism to organize files. That is an important point which I have
> met in Common Lisp. I haven't been at how to use the package in CL.

I wrote a bit about how I do this here:

  http://xach.livejournal.com/130040.html

Hope it helps.

Zach
From: Pascal J. Bourguignon
Subject: Re: How to organize a project via package
Date: 
Message-ID: <87bpnoinxi.fsf@galatea.local>
Elvis Nguyen <·······@gmail.com> writes:

> Dear all,
>
> In general, if we want to make a large program, we should have a
> mechanism to organize files. That is an important point which I have
> met in Common Lisp. I haven't been at how to use the package in CL.
>
> Now, I suppose that I have the files in the project:
> - main-frame.lisp
> - my-project.lisp
> - basic-functions.lisp
>
> I want to define a unique package in my project, called my-project.
> Currently, I am defining a package in main-frame, like this:
> (defpackage :my-project
>    (:use :cl :ltk))
> (in-package :my-project)
> .....
>
> And my-project.lisp and basic-functions.lisp use the same package my-
> project.
> But, it is very uncomfortable because if I want to check some
> operations in basic-functions, I must load the main-frame.lisp to
> define the package my-project at I run the test (only once time when I
> start sbcl)
>
> Thus, I have a question is: How do we organize a simple program via
> package? If so, you can give me a sample or tutorial.

Define all the packages of your project in a packages.lisp file, and
put in each source file an in-package form.  That's the standard
advise.

Indeed, you would have to load packages.lisp before loading any of the
other source files.

But if you avoid the IN-PACKAGE form in your other sources, then you
may not have to load packages.lisp before loading another source: this
way you could load the other source file in any package.

On the other hand, the other package (eg. COMMON-LISP-USER) from which
you'd load the source files might miss some use-package, shadow or
import that are defined in the defpackage forms in packages.lisp, so
it's probably better to stick to the standard layout and load both
packages.lisp and your source file.


Notice that the in-package form inside main-frame.lisp is inoperant
(if there's no following forms) because the *package* variable is
bound inside LOAD, so you cannot modify it (outside of LOAD, it keeps
its current value).  There's no use of in-package forms in
packages.lisp.


Finally, for a small-to-sizeable program, where you would have only
one package, I would avoid to use much packages other than CL (and
perhaps utility packages).  Better avoid name collisions, and qualify
all the symbols from the depended packages.


-- 
__Pascal Bourguignon__
From: Elvis Nguyen
Subject: Re: How to organize a project via package
Date: 
Message-ID: <71de51b4-9627-4e11-b0b6-e886897257bb@j12g2000vbl.googlegroups.com>
On Jul 13, 5:48 pm, ····@informatimago.com (Pascal J. Bourguignon)
wrote:
> Elvis Nguyen <·······@gmail.com> writes:
> > Dear all,
>
> > In general, if we want to make a large program, we should have a
> > mechanism to organize files. That is an important point which I have
> > met in Common Lisp. I haven't been at how to use the package in CL.
>
> > Now, I suppose that I have the files in the project:
> > - main-frame.lisp
> > - my-project.lisp
> > - basic-functions.lisp
>
> > I want to define a unique package in my project, called my-project.
> > Currently, I am defining a package in main-frame, like this:
> > (defpackage :my-project
> >    (:use :cl :ltk))
> > (in-package :my-project)
> > .....
>
> > And my-project.lisp and basic-functions.lisp use the same package my-
> > project.
> > But, it is very uncomfortable because if I want to check some
> > operations in basic-functions, I must load the main-frame.lisp to
> > define the package my-project at I run the test (only once time when I
> > start sbcl)
>
> > Thus, I have a question is: How do we organize a simple program via
> > package? If so, you can give me a sample or tutorial.
>
> Define all the packages of your project in a packages.lisp file, and
> put in each source file an in-package form.  That's the standard
> advise.
>
> Indeed, you would have to load packages.lisp before loading any of the
> other source files.
>
> But if you avoid the IN-PACKAGE form in your other sources, then you
> may not have to load packages.lisp before loading another source: this
> way you could load the other source file in any package.
>
> On the other hand, the other package (eg. COMMON-LISP-USER) from which
> you'd load the source files might miss some use-package, shadow or
> import that are defined in the defpackage forms in packages.lisp, so
> it's probably better to stick to the standard layout and load both
> packages.lisp and your source file.
>
> Notice that the in-package form inside main-frame.lisp is inoperant
> (if there's no following forms) because the *package* variable is
> bound inside LOAD, so you cannot modify it (outside of LOAD, it keeps
> its current value).  There's no use of in-package forms in
> packages.lisp.
>
> Finally, for a small-to-sizeable program, where you would have only
> one package, I would avoid to use much packages other than CL (and
> perhaps utility packages).  Better avoid name collisions, and qualify
> all the symbols from the depended packages.
>
> --
> __Pascal Bourguignon__

I have ever met a case. That is:
When I use in-package to change from CL-USER to my owned package. It
is ok. But I want to change from the package to CL-USER, it didn't
run. There is always an error, that: in-package hasn't defined. What
does that mean?
From: Joshua Taylor
Subject: Re: How to organize a project via package
Date: 
Message-ID: <h3fv20$j5i$1@news.eternal-september.org>
Elvis Nguyen wrote:
> 
> I have ever met a case. That is:
> When I use in-package to change from CL-USER to my owned package. It
> is ok. But I want to change from the package to CL-USER, it didn't
> run. There is always an error, that: in-package hasn't defined. What
> does that mean?

It sounds like your package didn't use CL, and so when the reader read 
(in-package ...) it saw a list whose CAR was my-package::in-package 
rather than CL:IN-PACKAGE.  If you evaluate your forms in the REPL, do 
you see something like what follows?  (I'm using LispWorks, but I bet 
other implementations have similar error messages.)

CL-USER > (defpackage #:without-cl
               (:use))
#<The WITHOUT-CL package, 0/16 internal, 0/16 external>

CL-USER > (in-package #:without-cl)
#<The WITHOUT-CL package, 0/16 internal, 0/16 external>

WITHOUT-CL > (in-package "CL-USER")

Error: Undefined operator IN-PACKAGE in form (IN-PACKAGE "CL-USER").
   1 (continue) Try invoking IN-PACKAGE again.
   2 Return some values from the form (IN-PACKAGE "CL-USER").
   3 Try invoking COMMON-LISP:IN-PACKAGE with the same arguments.
   4 Set the macro-function of IN-PACKAGE to the macro-function of 
COMMON-LISP:IN-PACKAGE.
   5 Try invoking something other than IN-PACKAGE with the same arguments.
   6 Set the symbol-function of IN-PACKAGE to another function.
   7 Set the macro-function of IN-PACKAGE to another function.
   8 (abort) Return to level 0.
   9 Return to top loop level 0.

Type :b for backtrace, :c <option number> to proceed,  or :? for other 
options
From: Pascal J. Bourguignon
Subject: Re: How to organize a project via package
Date: 
Message-ID: <87prc4gx0w.fsf@galatea.local>
Joshua Taylor <······@cs.rpi.edu> writes:

> Elvis Nguyen wrote:
>> I have ever met a case. That is:
>> When I use in-package to change from CL-USER to my owned package. It
>> is ok. But I want to change from the package to CL-USER, it didn't
>> run. There is always an error, that: in-package hasn't defined. What
>> does that mean?
>
> It sounds like your package didn't use CL, and so when the reader read
> (in-package ...) it saw a list whose CAR was my-package::in-package
> rather than CL:IN-PACKAGE.  If you evaluate your forms in the REPL, do
> you see something like what follows?  (I'm using LispWorks, but I bet
> other implementations have similar error messages.)
>
> CL-USER > (defpackage #:without-cl
>               (:use))
> #<The WITHOUT-CL package, 0/16 internal, 0/16 external>
>
> CL-USER > (in-package #:without-cl)
> #<The WITHOUT-CL package, 0/16 internal, 0/16 external>
>
> WITHOUT-CL > (in-package "CL-USER")
>
> Error: Undefined operator IN-PACKAGE in form (IN-PACKAGE "CL-USER").

In this case, you can get out by prefixing all the cl symbols:

(cl:defun fun (x y) (cl:+ (cl:* 2 x) y))
(fun 3 (cl:sin 4))
(cl:in-package "CL-USER")


-- 
__Pascal Bourguignon__
From: Pascal J. Bourguignon
Subject: Re: How to organize a project via package
Date: 
Message-ID: <87y6qsh2g1.fsf@galatea.local>
Elvis Nguyen <·······@gmail.com> writes:

> I have ever met a case. That is:
> When I use in-package to change from CL-USER to my owned package. It
> is ok. But I want to change from the package to CL-USER, it didn't
> run. There is always an error, that: in-package hasn't defined. What
> does that mean?

"in-package hasn't defined" is not an error message that I recognize
from any of the lisp implementations I know.  Perhaps it would be
better if you cut-and-pasted a real REPL interaction.


But that was the general meaning of my post, that given that another
package will not be configured with the same symbols than the one
designed specifically for your program, if you try to load your
sources in that other package, it will probably fail.

-- 
__Pascal Bourguignon__
From: Marco Antoniotti
Subject: Re: How to organize a project via package
Date: 
Message-ID: <362153ad-3c5e-4bcf-b752-fc7a92da3ec3@d34g2000vbm.googlegroups.com>
On Jul 13, 5:48 pm, ····@informatimago.com (Pascal J. Bourguignon)
wrote:
> Elvis Nguyen <·······@gmail.com> writes:
> > Dear all,
>
> > In general, if we want to make a large program, we should have a
> > mechanism to organize files. That is an important point which I have
> > met in Common Lisp. I haven't been at how to use the package in CL.
>
> > Now, I suppose that I have the files in the project:
> > - main-frame.lisp
> > - my-project.lisp
> > - basic-functions.lisp
>
> > I want to define a unique package in my project, called my-project.
> > Currently, I am defining a package in main-frame, like this:
> > (defpackage :my-project
> >    (:use :cl :ltk))
> > (in-package :my-project)
> > .....
>
> > And my-project.lisp and basic-functions.lisp use the same package my-
> > project.
> > But, it is very uncomfortable because if I want to check some
> > operations in basic-functions, I must load the main-frame.lisp to
> > define the package my-project at I run the test (only once time when I
> > start sbcl)
>
> > Thus, I have a question is: How do we organize a simple program via
> > package? If so, you can give me a sample or tutorial.
>
> Define all the packages of your project in a packages.lisp file, and
> put in each source file an in-package form.  That's the standard
> advise.

The horror.  The horror.  :)

Define each package in a <package-name>-pkg.lisp or <package-name>-
package.lisp *separatedly* and then organize your code in your system
definition utility (usually ASDF).

Cheers
--
Marco
From: Paul Donnelly
Subject: Re: How to organize a project via package
Date: 
Message-ID: <87ocroi6h1.fsf@plap.localdomain>
Marco Antoniotti <·······@gmail.com> writes:

> On Jul 13, 5:48 pm, ····@informatimago.com (Pascal J. Bourguignon)
> wrote:
>>
>> Define all the packages of your project in a packages.lisp file, and
>> put in each source file an in-package form.  That's the standard
>> advise.
>
> The horror.  The horror.  :)
>
> Define each package in a <package-name>-pkg.lisp or <package-name>-
> package.lisp *separatedly* and then organize your code in your system
> definition utility

> (usually ASDF).

The horror.  The horror.  ;)
From: Marco Antoniotti
Subject: Re: How to organize a project via package
Date: 
Message-ID: <040aca60-2eb6-4ecc-88ea-e415ee467c76@p23g2000vbl.googlegroups.com>
On Jul 14, 12:05 am, Paul Donnelly <·············@sbcglobal.net>
wrote:
> Marco Antoniotti <·······@gmail.com> writes:
> > On Jul 13, 5:48 pm, ····@informatimago.com (Pascal J. Bourguignon)
> > wrote:
>
> >> Define all the packages of your project in a packages.lisp file, and
> >> put in each source file an in-package form.  That's the standard
> >> advise.
>
> > The horror.  The horror.  :)
>
> > Define each package in a <package-name>-pkg.lisp or <package-name>-
> > package.lisp *separatedly* and then organize your code in your system
> > definition utility
> > (usually ASDF).
>
> The horror.  The horror.  ;)

The horror, the horror, the horror?!? :)

Cheers
--
Marco