Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: Getting at an AutoGenerated Package

  • To: mathgroup at smc.vnet.net
  • Subject: [mg52562] Re: [mg52554] Getting at an AutoGenerated Package
  • From: "David Park" <djmp at earthlink.net>
  • Date: Thu, 2 Dec 2004 02:21:13 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Why don't you create a real package? I have copied the code for a ToyPackage
at the end of this posting.

In this case the package was meant to be placed in a folder Algebra within
the ExtraPackages folder. Or, alternatively, it could be put in a folder
Algebra within an Applications folder. (The location of the Applications
folder can be found by evaluating $BaseDirectory or $UserBaseDirectory in
Mathematica.)

Your problem is caused by the fact that the Needs statement needs a file
path to get to the package. It knows how to find ExtraPackages or
Applications but it doesn't know where to go from there. So notice that in
ToyPackage the BeginPackage is

BeginPackage["Algebra`ToyPackage`"]

Algebra` tells the folder that ToyPackage will be in.

You would then load the package with

Needs["Algebra`ToyPackage`"]

Also note that the package itself is still stored under the name
ToyPackage.nb and ToyPackage.m.

When Mathematica evaluates a Needs statement it automatically starts looking
in StandardPackages, ExtraPackages and the various Applications folders. But
you have to give it the path from there.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/



From: AES/newspost [mailto:siegman at stanford.edu]
To: mathgroup at smc.vnet.net

OK, I created a notebook "myModules" containing a bunch of modules that
I want to use in my main notebook; set all the cells in this notebook to
Initialization cells; set the AutoGeneratedPackage option for this
notebook to Automatic; and indeed, each time I Save this notebook, it
creates a file "myModule.m" in the same folder as the "myModules"
notebook it's derived from, and the main notebook in which I want to use
these modules.

So, now how do I make this package available to my main notebook?
If I put an Input line

    Needs["myModules`"]

in my main notebook as advised by Maeder's book, I get an error message

    Needs::cxt: Context (string ending in `) expected at position 1 in
    Needs[myModules`].
___________________________________________________________________________

Notebook[{

Cell[CellGroupData[{
Cell["A Toy Package", "Title"],

Cell[BoxData[
    \(BeginPackage["\<Algebra`ToyPackage`\>"]\)], "Input",
  InitializationCell->True],

Cell[BoxData[
    \(\(Algebra`ToyPackage::usage = "\<This is a usage mesage for the \
entire package.\>";\)\)], "Input",
  InitializationCell->True],

Cell[BoxData[
    \(\(SquareTheQuantity::usage = "\<SquareTheQuantity[x] will take \
the square of x.\>";\)\)], "Input",
  InitializationCell->True],

Cell[BoxData[
    \(Begin["\<`Private`\>"]\)], "Input",
  InitializationCell->True],

Cell[BoxData[
    \(SquareTheQuantity[x_] := x\^2\)], "Input",
  InitializationCell->True],

Cell[BoxData[
    \(End[]\)], "Input",
  InitializationCell->True],

Cell[BoxData[
    \(\(Protect[Evaluate[$Context <> "\<*\>"]];\)\)], "Input",
  InitializationCell->True],

Cell[BoxData[
    \(EndPackage[]\)], "Input",
  InitializationCell->True]
}, Open  ]]
},
FrontEndVersion->"5.0 for Microsoft Windows",
ScreenRectangle->{{0, 1280}, {0, 941}},
AutoGeneratedPackage->Automatic,
WindowSize->{494, 740},
WindowMargins->{{81, Automatic}, {Automatic, 61}}
]





  • Prev by Date: Re: Re: How to solve nonlinear equations?
  • Next by Date: Re: ReplacePart position
  • Previous by thread: Getting at an AutoGenerated Package
  • Next by thread: Re: FourierTransform