MathGroup Archive 2004

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

Search the Archive

Re: including files

  • To: mathgroup at
  • Subject: [mg53215] Re: including files
  • From: Bill Rowe <readnewsciv at>
  • Date: Thu, 30 Dec 2004 01:38:25 -0500 (EST)
  • Sender: owner-wri-mathgroup at

On 12/28/04 at 11:12 PM, siegman at (AES/newspost) wrote:

>In article <cqrgrb$qhd$1 at>,
>Bill Rowe <readnewsciv at> wrote:

>>My suggestion would be to use a .m file. These are very easily

>>From within Mathematica, enter all of the expressions you want
>>evaluated into a notebook. Select the cells with those expressions
>>and set the cell properties as Initialization Cells. Finally, save
>>the notebook in package format using File->Save As
>>Special->Package Format.

>>Alternatively, a .m file can be created with any third party text
>>editor. Simply type the desired expressions and save the result
>>with an extension of .m.

>Packages can indeed be very useful, and this is good advice -- but
>in my experience at least, slightly incomplete:

>1)  There's the BeginPackage[---]; Begin[ ]  stuff and the End[ ];
>EndPackage[ ] stuff you're supposed to include -- I'm still not
>sure if you _must_ include those (documentation of packages is
>somewhat arcane); and

The BeginPackage is only needed if you want the expressions in a separate context. This is often quite desirable. But it is not necessary. 

Without the BeginPackage ... End, everything is from the .m file is loaded into the Global context. If the .m file only contains a few simple functions, this may be quite acceptable.

For myself, I use both. I use the BeginPackage ... End when I am creating a fairly general set of functions I expect to use widely. I particularly use this when part of the functionality of the package relies on intermediate functions not intended to be used directly.

OTOH, when I want to quickly save a few specialized functions, I usualy simply put those in a .m file without the BeginPackage stuff.

>2)  You have to Save the package in the right place, and maybe in a
>folder with the right name to access it; and

Certainly true and applies to any file being saved.

>3)  I still not clear about the complex ways in which creating and
>using a package can mess with scopes and contexts, nor whether, if
>you edit the .nb->.m package combo during a session, you have to
>restart a new session to get the edits properly recognized.

It is possible to edit either a .nb or .m file and have the edits without restarting. But the details depend on how the package is written. I usually start my packages with the following:



This ensures the package can be re-loaded without restarting.
To reply via email subtract one hundred and four

  • Prev by Date: Re: Re: Zero testing
  • Next by Date: RE: DelaunayTriangulation
  • Previous by thread: Re: including files
  • Next by thread: Forged postings to various newsgroups