Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*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 2000

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

Search the Archive

Re: functions, packages, and contexts

  • To: mathgroup at smc.vnet.net
  • Subject: [mg25035] Re: functions, packages, and contexts
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Fri, 1 Sep 2000 21:57:41 -0400 (EDT)
  • References: <8one3u$oh4@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

matt,
I'm not too clear about what is happening, but here are some suggestions.

Put your packages in the the directory that with Mathematica 4.0 on Windows is
        ...  Wolfram Research\Mathematica\4.0\AddOns\ExtraPackages\MyPackages

Then, if your function MW is in the package "Weight.m" you should give this
package the context "MyPackages`Weight`" via

    BeginPackage["MyPackages`Weight`"]

This package will be loaded by

    <<MyPackages`Weight`"

Then, to be able to use MW  inside the package "MyPackages`React`", you need
to begin the latter's code with

    BeginPackage["MyPackages`React`", "MyPackages`Weight`"]

Here we are telling Mathematica that "MyPackages`Weight`" is a "needed" package (any
number of needed packages may be included) This will cause it to add the
context  "MyPackages`Weight`" to the context search path (given by
$ContextPath) and also evaluate Needs["MyPackages`Weight`" ], this will load
the package if it has not already been loaded.

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

<Matt.Johnson at autolivasp.com> wrote in message
news:8one3u$oh4 at smc.vnet.net...
> Dear All -
>
> I am new to the package-writing frontier and am running into a problem I
> can't seem to overcome.  The first package I have defines a molecular
> weight (MW) function, which takes a molecule as an argument and returns
the
> molecular weght.  The molecule must be of the form C1O2, for carbon
> dioxide, for example (each element is followed by the number of atoms of
> that element). The problem I have is that now I am using that package
> within another package.  Because the context has been changed, the
> molecules are sent to the MW function as Global`MyPackages`React`C1O2
where
> React is the package I am working in.  The MW function has been written to
> pick out elements and numbers, but cannot handle the additional input of
> the context path.   Is there an easy fix for this, i.e. is there a way to
> send the MW function just the molecular notation within the package
without
> including the context?  Or do I have to define the MW function to pick off
> the C1O2 from the variable for it to work?
>
> Thanks-
>
> matt
>
>




  • Prev by Date: Re: Exporting to MS Word
  • Next by Date: Re: ButtonBox, styles, GraphicsGenerator.nb
  • Previous by thread: RE: functions, packages, and contexts
  • Next by thread: Re: Re : Mathematica PC to MAC problems