Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: Saving Packages (was: Re: importing nb files)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg86793] Re: [mg86775] Saving Packages (was: Re: importing nb files)
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Fri, 21 Mar 2008 01:53:22 -0500 (EST)
  • References: <fro3a6$i8l$1@smc.vnet.net> <frqpnm$505$1@smc.vnet.net> <24973910.1206007736951.JavaMail.root@m08>
  • Reply-to: drmajorbob at longhorns.com

Make a=2 an initialization cell.

Bobby

On Thu, 20 Mar 2008 02:58:16 -0500, alexxx.magni at gmail.com  
<alexxx.magni at gmail.com> wrote:

> 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 tha=
t
>> > needed breaking up in different notebooks, so I seldom used the Get=

>> > (<<) function, but I seemed to remember this function would allow m=
e
>> > 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 packag=
e
>> 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
>
>



-- =

DrMajorBob at longhorns.com


  • Prev by Date: Re: texture mapping/memory leak?
  • Next by Date: Re: Saving Packages
  • Previous by thread: Saving Packages (was: Re: importing nb files)
  • Next by thread: texture mapping/memory leak?