Saving Packages (was: Re: importing nb files)

*To*: mathgroup at smc.vnet.net*Subject*: [mg86775] Saving Packages (was: Re: importing nb files)*From*: "alexxx.magni at gmail.com" <alexxx.magni at gmail.com>*Date*: Thu, 20 Mar 2008 02:58:16 -0500 (EST)*References*: <fro3a6$i8l$1@smc.vnet.net> <frqpnm$505$1@smc.vnet.net>

Update: Starting by creating a new package window, the a=2 definition generates a .m file containing: (* ::Package:: *) a=2 so: without the (* ::Input:: *) line, and with the definition not commented. BUT - this remains a problem, if one doesnt want to start right from scratch with a package, but instead convert a notebook to a package: this seems impossible! Alessandro ______________ oh, damn, you're right - now I remember! Yet... 1) creating a notebook containing just: a=2 2) savinga as package file as "test.m" 3) importing it: <<"test.m" I get no error, but "a" remains undefined. (version 6.0.2 here) Looking for the problem, I noticed that the source of test.m is: (* ::Package:: *) (* ::Input:: *) (*a:=2*) commented out !!! I saved as package another bigger .nb file, and it did the same: it comments out everything. When I took away the (* *) of course Get[] worked. So? Maybe the right question is "How do I create a Package?" Because obviously "Save As->Mathematica Package (.m)" is crippled. David Bailey ha scritto: > alexxx.magni at gmail.com wrote: > > a very basic question - sorry for that... > > > > probably it's me, almost never having programmed large projects that > > needed breaking up in different notebooks, so I seldom used the Get > > (<<) function, but I seemed to remember this function would allow me > > to Import&evaluate a notebook in another. > > > > So, defining simply a=2 in a notebook test.nb, when I executed: > > > > <<"test.nb" > > > > I obtained: > > > > Notebook[{Cell[ > > CellGroupData[{Cell[BoxData[RowBox[{"a", "=", "2"}]], "Input", > > CellChangeTimes -> {{3.41474*10^9, 3.41474*10^9}}], > > Cell[BoxData["2"], "Output", CellChangeTimes -> {3.41474*10^9}]}, > > Open]]}, WindowSize -> {640, 750}, > > WindowMargins -> {{150, Automatic}, {Automatic, 52}}, > > FrontEndVersion -> "6.0 for Linux x86 (32-bit) (February 7, 2008)", > > StyleDefinitions -> "Default.nb"] > > > > (a verbose output which I didnt remember) and, moreover, my "a" > > variable still remains undefined! > > What I'm missing (or forgetting)? > > > > thanks! > > > > Alessandro > > > You are forgetting that Get reads .m files (sometimes known as package > files), not notebooks. However, in 6.0 .m files can be edited almost as > if they were notebooks and non-code information such as headings is > stored in the .m file as comments. > > Note also, that if you open a notebook and evaluate it, and then open > another and evaluate that also, the second evaluation will use any > relevant definitions from the first one. > > David Bailey > http://www.dbaileyconsultancy.co.uk