From: ···········@gmail.com
Subject: problem with packages
Date: 
Message-ID: <1178551669.536605.143320@u30g2000hsc.googlegroups.com>
I'm writing a package called "play" that plays a game, with a top
level function called "play-game".  I'm also writing a package called
"find" to go out in the world and find a game to play, with a top
level function called "find-game".

When play::play-game finishes, I would like for it to go into the
world and find another game by calling find::find-game.  When
find::find-game has found a game, I would like for it to call
play::play-game.

So, how do I build these packages?  Each refers to the other, so which
one gets built first?  If it finds a package name it doesn't
recognize, it just dies.

Thanks in advance!

From: Dan Bensen
Subject: Re: problem with packages
Date: 
Message-ID: <f1nho6$m2o$1@wildfire.prairienet.org>
···········@gmail.com wrote:
> So, how do I build these packages?  Each refers to the other, so which
> one gets built first?  If it finds a package name it doesn't
> recognize, it just dies.

Make a controller package with a function that calls both of
your functions.  Make each function, find and play, return
control to the main function so it can call the other one.

-- 
Dan
www.prairienet.org/~dsb/
From: Tim Bradshaw
Subject: Re: problem with packages
Date: 
Message-ID: <f1nj3b$r11$1$8302bc10@news.demon.co.uk>
On 2007-05-07 16:27:49 +0100, ···········@gmail.com said:

> When play::play-game finishes, I would like for it to go into the
> world and find another game by calling find::find-game.  When
> find::find-game has found a game, I would like for it to call
> play::play-game.

(in-package :play)

(defun play-game (... &key (finder nil) ...)
  ...
  (when finder (funcall finder ... :player #'play-game)))

Note although this does what you want it's a bad solution because it 
recurses.  You almost certainly want to have a finder function which 
just finds and a player function which just plays, and a controller 
function which looks pretty much like:

(defun controller (... &key finder player)
  (loop for game = (and finder (funcall finder ...))
        while game
        do (funcall player game ...)))
From: Thomas A. Russ
Subject: Re: problem with packages
Date: 
Message-ID: <ymik5vkxhth.fsf@sevak.isi.edu>
···········@gmail.com writes:

> I'm writing a package called "play" that plays a game, with a top
> level function called "play-game".  I'm also writing a package called
> "find" to go out in the world and find a game to play, with a top
> level function called "find-game".
> 
> When play::play-game finishes, I would like for it to go into the
> world and find another game by calling find::find-game.  When
> find::find-game has found a game, I would like for it to call
> play::play-game.
> 
> So, how do I build these packages?  Each refers to the other, so which
> one gets built first?  If it finds a package name it doesn't
> recognize, it just dies.

It isn't clear at all to me why you want to have these functions in
different packages.  Since they are all part of one combined system, I
would use the same Lisp package for both of them.

If you want to separate the functioanlity, put the code for playing the
game in one file, and that for finding additional games in another
file.  I don't think you need to get the package system involved in any
meaningful way at all.

Use a single package.

-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Alan Crowe
Subject: Re: problem with packages
Date: 
Message-ID: <86ejlsjo51.fsf@cawtech.freeserve.co.uk>
···········@gmail.com writes:

> I'm writing a package called "play" that plays a game, with a top
> level function called "play-game".  I'm also writing a package called
> "find" to go out in the world and find a game to play, with a top
> level function called "find-game".
> 
> When play::play-game finishes, I would like for it to go into the
> world and find another game by calling find::find-game.  When
> find::find-game has found a game, I would like for it to call
> play::play-game.
> 
> So, how do I build these packages?  Each refers to the other, so which
> one gets built first?  If it finds a package name it doesn't
> recognize, it just dies.

I would create a file "packages.lisp"

(defpackage "PLAY"
  (:use "CL")
  (:export "PLAY-GAME"))

(defpackage "FIND"
  (:use "CL" "PLAY")
  (:export "FIND-GAME"))

(use-package "FIND" "PLAY")

In the first form PLAY cannot use FIND because it has not
yet been defined. In the second form FIND can use PLAY
because it is defined second. In the third form we add FIND
to the use list of PLAY. (like fixing up a forward reference
in a single pass assembler :-)

No cycle is created because the external symbols of the used
package are merely internal symbols of using package so
don't chain on.

Then I put half my code in play.lisp

(in-package "PLAY")

(defun play-game ()
  (print 'playing)
  (unless (zerop (random 4))
    (find-game)))

and half my code in find.lisp

(in-package "FIND")

(defun find-game ()
  (print 'searching)
  (unless (zerop (random 4))
    (play-game)))

and, provided that I load packages.lisp first, everything
works

* (load "packages.lisp")

; Loading #p"/home/alan/Learning/lisp/packages/game-example-for-c.l.l./packages.lisp".
T
* (load "play.lisp")

; Loading #p"/home/alan/Learning/lisp/packages/game-example-for-c.l.l./play.lisp".
T
* (load "find.lisp")

; Loading #p"/home/alan/Learning/lisp/packages/game-example-for-c.l.l./find.lisp".
T

* (find:find-game)

FIND::SEARCHING 
PLAY::PLAYING 
FIND::SEARCHING 
PLAY::PLAYING 
FIND::SEARCHING 
PLAY::PLAYING 
FIND::SEARCHING 
PLAY::PLAYING 
FIND::SEARCHING 
PLAY::PLAYING 
NIL
 
Alan Crowe
Edinburgh
Scotland