Re: writing programs
- To: mathgroup at smc.vnet.net
- Subject: [mg13476] Re: writing programs
- From: "Paul A. Rombouts" <paromb at worldonline.nl>
- Date: Sun, 26 Jul 1998 02:33:36 -0400
- Organization: World Online
- References: <6p6rgt$5lf@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
John M. Dlugosz wrote in message <6p6rgt$5lf at smc.vnet.net>... >How do you write programs in Mathematica? I'm asking about the >mechanics of preparing the files, not the language reference. > >I looked at a simple .m file, and see that it's plain text as I would >input it. [snip] >Second, typing input text is fine for C++ or Perl, but won't let me get >all the fancy stuff in Mathematica. I'd rather use the notebook >interface. > >This package I'm looking at says I can rename the .nb file to .m and it >will work, too. But I wonder how? If all the cells are executed in >order when I load the "package", what happens to all the examples and >text? > >Just what happens when I "load" such a renamed file as a package? > >--John Hi John, I think you'll find answers to most of your questions in sections 1.11.1 and 2.11.1 of the Mathematica book (third edition). When I write packages I usually create a notebook using the front end. Then I mark the cells containing code I want to include in the package as initialization cells and save the notebook. Mathematica automatically asks me whether I want to create an "Auto Save Package". When you answer affirmatively, "This will cause the front end to automatically maintain a package (.m) in the same directory as the notebook. The package will contain all the initialization cells from the notebook; it will be updated each time the notebook is saved." You can look at the files ChaosGame.nb and ChaosGame.m in the subdirectory AddOns\ExtraPackages\ProgrammingInMathematica\ of the main Mathematica directory for an example of a package made this way. In case Mathematica fails to ask you if you want to create an "Auto Save Package", you can set the option Notebook Options/File Options/AutoGeneratedPackage using the option inspector. I hope this helps. Paul A. Rombouts <P.A.Rombouts at phys.uu.nl>