MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Package Puzzlers?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg35767] RE: [mg35737] Package Puzzlers?
  • From: "David Park" <djmp at earthlink.net>
  • Date: Tue, 30 Jul 2002 07:22:19 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

AES,

I am just going to answer your first question.

Yes, it is possible to write packages with cell grouping and headers and
with text cell exposition. In my opinion, that it the way it should be done.

Many package writers, even many who are extremely good at Mathematica, take
an arcane approach to writing packages. Many even recommend writing packages
in a text editor outside of Mathematica! (There is also the question of
where to put packages. Many writers will put them anywhere except the
ExtraPackages folder, which is where they should be if you want them to
behave like standard packages.) I think all of this confusion arises because
the fundamentals of package writing are poorly documented.

To write a package just start with a standard Default Mathematica notebook.
Write your BeginPackage statement, usage statements, function definitions,
etc., in the normal way. As much as possible, put each statement in a
separate cell. Make all the Input cells Initialization cells. When you save
the notebook choose the option "Create AutoSave Package". The .m package
file will automatically be created, and it will be automatically updated
everytime you change and save the .nb file. YOU SHOULD NEVER HAVE TO
DIRECTLY EDIT OR EVEN LOOK AT A .m FILE. (The only reason to look at a .m
file is to look at somebody else's code, if they haven't provided you with
the .nb file. If you want other people to have direct access to your package
code, give them the .nb file.) You can do all your work in the .nb file.
Then you can use all the normal FrontEnd facilities.

This means that you can use cell grouping with group headers and text cells.
These are automatically excluded when the .m file is created. I often use an
Annotation Section and an Implementation Section. I use SubSections for the
Usage Statements and Package Code. I use SubSubSections for each routine and
sometimes for each usage statement. So it is possible to group and organize
the package code in just the way you desire.

I will send you a sample package notebook if you wish.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/

________________________________________________
From: AES [mailto:siegman at stanford.edu]
To: mathgroup at smc.vnet.net


I want to make some simple packages. Not even much worried about
contexts or protection, since all symbols likely to be global anyway.

But I would like to put multiple cells including notebook type header
cells in these packages -- primarily, I suppose, because this makes the
code so much easier to edit and more readable, for me anyway, than using
(*  *) style comments.

1)  All the package demos and templates I've seen seem to be single
cells (though that's not always very clearly stated).  Do packages have
to be single cells?  Or can they have multiple cells, including header
cells?



  • Prev by Date: Re: Re: Question about Replace
  • Next by Date: RE: Re: More weird integration issues...
  • Previous by thread: Re: Package Puzzlers?
  • Next by thread: Work with Contexts