MathGroup Archive 2011

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

Search the Archive

Re: package trouble

  • To: mathgroup at smc.vnet.net
  • Subject: [mg117913] Re: package trouble
  • From: David Bailey <dave at removedbailey.co.uk>
  • Date: Mon, 4 Apr 2011 06:29:59 -0400 (EDT)
  • References: <in9jte$f7s$1@smc.vnet.net>

On 03/04/2011 11:58, Alexandru Chirvasitu wrote:
> Hi,
>
> This is a very frustrating problem. I'd appreciate any help you can provide.
>
> I'm trying to write a package; this has happened several times, with
> several packages, but most recently, I tried a very simple one that
> was suggested on this forum a while back, actually, by another user
> with a very similar problem:
>
> BeginPackage["anything`"]
> definition::usage="blablabla";...
> Begin["`Private`"]
> functions
> End[]
> Protect[functions]
> EndPackage[]
>
> I made sure the cell is an Initialization Cell, and I changed the
> style to "code". I saved in an appropriate directory both as
> anything.nb and anything.m, and then tried to read in the package with
>
> <<anything`
>
> What I got as output was
>
> Notebook[{Cell[
>     BoxData[{RowBox[{"BeginPackage", "[", "\"anything`\"", "]"}], "
>       ", RowBox[{RowBox[{RowBox[{RowBox[{"definition", "::", "usage"}],
>              "=", "\"blablabla\""}], ";"}], "..."}], "
>       ", RowBox[{"Begin", "[", "\"`Private`\"", "]"}], "
>       ", "functions", "
>       ", RowBox[{"End", "[", "]"}], "
>       ", RowBox[{"Protect", "[", "functions", "]"}], "
>       ", RowBox[{"EndPackage", "[", "]"}]}], "Code",
>     InitializationCell ->  True,
>     CellChangeTimes ->  {{3.51079*10^9, 3.51079*10^9}}]},
>   WindowSize ->  {715, 559},
>   WindowMargins ->  {{96, Automatic}, {4, Automatic}},
>   FrontEndVersion ->
>    "8.0 for Microsoft Windows (32-bit) (November 7, 2010)",
>   StyleDefinitions ->  "Default.nb"]
>
> If I try Needs["anything`"] I first get
>
> Needs::nocont: Context a` was not created when Needs was evaluated.>>
>
> and then th same RowBox mess as above.
>
> Does anybody have any idea what's going on? I should say, it has
> worked a bunch of times, but I can't see any pattern to it: most of
> the times it behaves like this, and only very rarely, it will go
> through. I should mention this is Mathematica 8, and the system is
> Windows XP.
>
> The other thread on MathGroup that I was referring to is here:
>
> http://forums.wolfram.com/mathgroup/archive/1999/Mar/msg00051.html
>
> There is only one response, regarding the package having to have the
> same name as the context (which is the case here), and also the need
> for the cell to be initialization (which again, is the case here).
>
> Please help; I'm desperate here :).
>
>
> Thank you,
>
> Al
>
Clearly you have ended up storing a notebook in a .m file. I'd start by 
renaming the file as a .nb file (if you want to recover its contents).

My way to convert a notebook into a new package is to copy/paste the 
cells across, and change the Input cells into Code cells, before saving 
the result as a .m file.

There may be a better way to do this, but to be honest, I do almost all 
my work in .m files directly. The frontend editor works beautifully on 
these files, gives you headings and text cells, and you can even execute 
them and look at the results as if it were a notebook. The main 
difference is that output is not saved when you save the file, which I 
find rather convenient.

David Bailey
http://www.dbaileyconsultancy.co.uk



  • Prev by Date: Re: package trouble
  • Next by Date: Integation Anomoly
  • Previous by thread: Re: package trouble
  • Next by thread: Manipulate, how to slowdown animation