From: Jonathan BAILLEUL
Subject: Help required: How to generate a package?
Date: 
Message-ID: <38D104D6.A68CBC03@emi.u-bordeaux.fr>
Hello.

I have finished a small package for handling matrices. It includes 3
constants: the slots type, the length and the width. All other
operations (basic accessors, few arithmetic operations) are fully
generic and use the values of these constants.

So I can virtually handle any type of 2-dimensionnal matrix, provided
that I modify BY HAND the value of the constants in the file.
I want to be able to dynamically include in the current environment a
new named package, specialized for operations on a certain type of
matrices.

I started writing a macro, with for arguments the length, width, type,
and name of the package. It effectively generates the code I expected
(cf. the sample below), but the problem is that it does not work:
exported functions are not defined (I use CMUCL).

I noticed that when I include the code in a file, and then if I load
that file, everything works exactly as I had expected. Seems like the
loading of the file is necessary to add a new package in the
environment.

Can someone help me? How can I make this approach successful, and whose
other approaches are more relevant.
Thank you very much.



PS: the promised sample

(IN-PACKAGE 'GLOS-MATRIX-MAT)

(DEFPACKAGE "GLOS-MATRIX-MAT"
  (:USE "COMMON-LISP")
  (:EXPORT "MAKE-NULL")
  (:NICKNAMES "MAT")
  (:DOCUMENTATION
   "Generated package providing facility for 4 4 'DOUBLE-FLOAT matrix
handling"))
 
(DEFUN MAKE-NULL ()
  "create a matrix with null slots"
  (MAKE-ARRAY (* 4 4) :ELEMENT-TYPE 'DOUBLE-FLOAT))

(IN-PACKAGE 'COMMON-LISP)

-- 
----------------------------------------------
Jonathan BAILLEUL (········@emi.u-bordeaux.fr)
Maitrise Informatique, Universite Bordeaux I

From: Barry Margolin
Subject: Re: Help required: How to generate a package?
Date: 
Message-ID: <A_7A4.14$Hp4.393@burlma1-snr2>
In article <·················@emi.u-bordeaux.fr>,
Jonathan BAILLEUL  <········@emi.u-bordeaux.fr> wrote:
>I noticed that when I include the code in a file, and then if I load
>that file, everything works exactly as I had expected. Seems like the
>loading of the file is necessary to add a new package in the
>environment.

Of course it is.  Just as you have to load the file that contains a
function definition in order for it to be added to the environment, you
have to load the file that contains a package definition to add it to the
environment.

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Tim Bradshaw
Subject: Re: Help required: How to generate a package?
Date: 
Message-ID: <ey3zory26c9.fsf@cley.com>
* Barry Margolin wrote:

> Of course it is.  Just as you have to load the file that contains a
> function definition in order for it to be added to the environment, you
> have to load the file that contains a package definition to add it to the
> environment.

I think the OP has some other problem.  Tghe macro probably expands to
something like:

	(progn
	  (defpackage ...)
	  (in-package ...)
	  (defun something ...))

and the problem is that SOMETHING is interned in the `wrong' package
because it's been read long ago.  My guess is he's editing out the
body of the progn and putting it in a file and that works.

This is probably hard to do right -- you either need to have the
package created during the macro expansion (so you can then create the
symbol), or you need to do some deviousness with delaying the naming
of the function until later on -- perhaps something like:

	(setf (symbol-function (intern ...)) ...)

I think the right answer isn't the using the package system to do what
he's trying to do though -- I'm not sure what the actual solution is.

Or maybe I'm confused.
From: Lieven Marchand
Subject: Re: Help required: How to generate a package?
Date: 
Message-ID: <8ar9et$mam$1@newnews1.news.nl.uu.net>
Jonathan BAILLEUL <········@emi.u-bordeaux.fr> writes:

> I have finished a small package for handling matrices. It includes 3
> constants: the slots type, the length and the width. All other
> operations (basic accessors, few arithmetic operations) are fully
> generic and use the values of these constants.

This seems like a very Ada approach. I'm not sure this maps well to CL. 

If you insist on doing this, there is a functional interface to the
package system. Look at stuff like MAKE-PACKAGE, EXPORT, USE-PACKAGE
etc.

-- 
Lieven Marchand <···@bewoner.dma.be>
If there are aliens, they play Go. -- Lasker
From: Jason Kantz
Subject: Re: Help required: How to generate a package?
Date: 
Message-ID: <wkd7ottyo8.fsf@kantz.com>
This reminded me of something I wanted to ask about generating
packages.  

Does anyone have a utility for collecting all the function
names in an emacs buffer?
From: Pierre R. Mai
Subject: Re: Help required: How to generate a package?
Date: 
Message-ID: <87vh2lecsb.fsf@orion.dent.isdn.cs.tu-berlin.de>
Jason Kantz <·····@kantz.com> writes:

> This reminded me of something I wanted to ask about generating
> packages.  
> 
> Does anyone have a utility for collecting all the function
> names in an emacs buffer?

I'd be amazed if ILISP and ELI don't contain the low-level stuff to do 
this, and maybe even some nice interface to it.

If you don't need to be 100% syntactically correct, a simple grep with 
a suitable regexp should suffice...  I'm a bit in a hurry now, so I
haven't got the time to write the 5-10 lines of code to do this and
insert the export clause automagically, so you'll have to hack on this
yourself... ;)

Regs, Pierre.

-- 
Pierre Mai <····@acm.org>         PGP and GPG keys at your nearest Keyserver
  "One smaller motivation which, in part, stems from altruism is Microsoft-
   bashing." [Microsoft memo, see http://www.opensource.org/halloween1.html]