[Date Index]
[Thread Index]
[Author Index]
RE: Loading packages within packages
*To*: mathgroup at smc.vnet.net
*Subject*: [mg30256] RE: [mg30240] Loading packages within packages
*From*: "David Park" <djmp at earthlink.net>
*Date*: Sat, 4 Aug 2001 01:14:24 -0400 (EDT)
*Sender*: owner-wri-mathgroup at wolfram.com
Oliver,
I find the easiest way to write a package is as a regular notebook. Put each
statement in as an individual cell. Then make all the cells initialization
cells. Then when you first save the notebook choose to create an autosave
package. That is what creates the .m file. Each time you edit the package
and save it, a new copy of the .m file will also be saved. You do not have
to write the .m file yourself.
Where to put the packages? People do different things, but I find this the
simplest approach. Put the package notebook in the AddOns/ExtraPackages
directory. Create subfolders there which mirror most of the subfolders in
the AddOns/StandardPackages directory. Packages placed in the ExtraPackages
directory will work just like the standard Mathematica packages. Mathematica
automatically looks there whenever you load a package. But the ExtraPackages
folder keeps them out of the way of the standard packages.
As an example: Suppose you write a package "CliffordAlgebra". Perhaps you
feel that this should be grouped with "Algebra" packages. Create an Algebra
folder in the ExtraPackages folder. Name your package notebook
CliffordAlgebra.nb. In your notebook use
BeginPackage["Algebra.CliffordAlgebra",{...}]
When you save your notebook for the first time choose to create an AutoSave
Package. That will create a file CliffordAlgebra.m in the same folder, and
this file is the actual package file.
Now, as to your problems.
When you use a default parameter in a package routine definition you have to
use the full context name, else the current package context will be used. So
you might want to use
MyFunctionA[a_:Global`defaultA]:=ExternalFunctionA[a]
or perhaps
MyFunctionA[a_:Algebra`PackageA`defaultA]:=ExternalFunctionA[a]
I don't know why your statement did not recognize ExternalFunctionA. Perhaps
it was not in the package by that name, or Mathematica did not actually find
the package. Or perhaps it is because your entire package was in one
statement. I am not certain. Normally you should be able to write the
statement as above.
David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/
> From: Oliver Friedrich [mailto:oli.fri at gmx.de]
To: mathgroup at smc.vnet.net
> Sent: Friday, August 03, 2001 12:56 AM
> To: mathgroup at smc.vnet.net
> Subject: [mg30256] [mg30240] Loading packages within packages
>
>
> Hallo NG,
>
> I have some trouble with a self written package that reqires
> other packages.
> It looks like this:
>
> BeginPackage["MyPackage`",{"PackageA`"}]
>
> MyFunctionA::usage=
> "blablabla"
>
> Begin["`Private`"]
>
> MyFunctionA[a_:defaultA]:=ExternalFunctionA[a]
>
> End[]
>
> EndPackage[]
>
> Now my problems:
> ExternalFunctionA is defined in PackageA`. When I load this
> package and use
> MyFunctionA, the following happens:
>
> In:=
> MyFunctionA[]
>
> Out:=
> MyPackage`Private`ExternalFunctionA[MyPackage`Private`defaultA]
>
> 1. Why is ExternalFunctionA connected to MyPackage`Private`
> context and not
> to PackageA` context? Of course, in this case ExternalFunctionA
> doesn't work
> ! What am I doing wrong?
>
> 2. How can I supress the complete context of defaultA? When I call
> MyFunctionA with the parameter it looks like this:
>
> In:=
> MyFunctionA[parameter]
>
> Out:=
> MyPackage`Private`ExternalFunctionA[parameter]
>
> 3. A more general question:What's the correct way to write *.m files,
> especially how to save them correctly. The way I do seems to be a
> little bit
> weird to me
>
> I have the Mathematica book, but this one is not explained thouroughly
> enough. I'm running Version 3.0 !
>
> Thanks for any suggestions
>
> Oliver Friedrich
>
>
>
>
Prev by Date:
**Re: Any quantum chemists / physicists?**
Next by Date:
**Re: Loading packages within packages**
Previous by thread:
**Loading packages within packages**
Next by thread:
**Re: Loading packages within packages**
| |