MathGroup Archive 2001

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

Search the Archive

Re: Loading packages within packages

  • To: mathgroup at smc.vnet.net
  • Subject: [mg30264] Re: Loading packages within packages
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Sat, 4 Aug 2001 01:14:30 -0400 (EDT)
  • References: <9kdbv0$f4u$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Oliver,

I'm not getting the same as you, so let me say what I am doing and then deal
with the problem of defaultA.

I make two .m files in the directory AddOns\ExtraPackages (actually by
creating a new text file and typing)

The first, MyPackage.m, with text

        BeginPackage["MyPackage`",{"PackageA`"}]

        MyFunctionA::usage=
        "blablabla"

        Begin["`Private`"]

        MyFunctionA[a_:defaultA]:=ExternalFunctionA[a]

        End[]

        EndPackage[]

The second, PackageA.m, with text

        BeginPackage["PackageA`"]

        ExternalFunctionA::usage=
        "blablabla"

        Begin["`Private`"]

        End[]

        EndPackage[]

After

        <<MyPackage`

MyFunctionA   has been created as  MyPackage`MyFunctionA
defaultA    has been created as MyPackage`Private`defaultA
PackageA.m  has been loaded
ExternalFunctionA   has been created as PackageA`ExternalFunctionA

The current context is "Global`"
and the current context path is
{"MyPackage`","PackageA`","Global`","System`"}

Now I get

        MyFunctionA[]

                ExternalFunctionA[MyPackage`Private`defaultA]

Only the short form of ExternalFunctionA  is displayed because
PackageA`ExternalFunctionA the unique amongst those long names with an
active context (equal to the current context or in the current context
path).

Since the context of  MyPackage`Private`defaultA  is not active it is
displayed in full.

We can deal with this by giving    defaultA    a usage message ( before
Begin["`Private"]) in either of the packages.

Here is what happens after I have added the usage message to MyPackage.m.

        <<MyPackage`

        MyFunctionA[]

                ExternalFunctionA[MyPackage`Private`defaultA]

PROBLEM! How is this when MyPackage`defaultA   has been created?
The point is that the old long symbol   MyPackage`Private`defaultA   is
still around from the earlier loading, and  when  default  is found in
MyPackage.m    the current context is "MyPackage`Private` and so
MyPackage`Private`defaultA  used in preference to MyPackage`defaultA

So, quit the kernel and start afresh

        Quit[]

        <<MyPackage`

        MyFunctionA[]

                ExternalFunctionA[defaultA]
--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"Oliver Friedrich" <oli.fri at gmx.de> wrote in message
news:9kdbv0$f4u$1 at smc.vnet.net...
> 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: Loading packages within packages
  • Next by Date: Re: Combining several InterploatingFunction to one
  • Previous by thread: RE: Loading packages within packages
  • Next by thread: Re: Loading packages within packages