MathGroup Archive 1998

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

Search the Archive

How to load user defined packages?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg14357] How to load user defined packages?
  • From: sean_ross_at_pl-04m3 at smtpgw1.plk.af.mil
  • Date: Thu, 15 Oct 1998 00:28:59 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

     I am going through David Wagners Power Programming book and have 
     finally got to chapter 8, about packages and I am totally stuck. 
He 
     gives the code for a simple package, tells us to type it in, save
it 
     as a package and then verify that we can load it.  I typed the code
in 
     and evaluated it to make sure it ran from a notebook.  I then saved

     the code as a package and placed it in the D:\Program 
     Files\Mathematica301\AddOns\ExtraPackages  directory because that 
     directory was already on the $Path list.  When I attempt to load
the 
     package using:
     
     Needs["LCGRandom`"]    
     --Or--
     Needs["LCGRandom`",
       "D:\Program
Files\Mathematica301\AddOns\ExtraPackages\LCGRandom.m"]
     --Or--
     Needs["Program
Files`Mathematica301`AddOns`ExtraPackages`LCGRandom`"]
     
     I get the same error message, that the context LCGRandom` was not 
     created when needs evaluates.  The package definitions are not
loaded. 
      I have tried exiting and re-starting Mathematica, rebooting the 
     machine, loading the package file into different directories etc. 
All 
     with the same result.
     
     Can anyone help me?
     
     Sean Ross
     
     Please respond to rosss at plk.af.mil or seanross at worldnet.att.net as
I 
     no longer subscribe to mathgroup.
     
     
     
     The code for the package follows:
     
     
     BeginPackage["LCGRandom`"]
     LCGSetSeed::usage=
       "LCGSetSeed[x] sets the LCG\ randomnumber generator's seed to the

     integer \
     x.";
     LCGRandom::usage="LCGRandom[] generates a\
                uniformly distributed random number in the range\
                {0.,1.} using a linear congruential generator.";
     
     Begin["`Private`"]
     
     modulus=2^31-1;
     seed=1;
     
     LCGSetSeed[x_Integer/;1<=seed<modulus]:=seed=x;
     
     LCGRandom[]:=(
        seed=Mod[7^5 * seed,modulus];
        N[seed/modulus])
     
     End[]
     
     Protect[LCGSetSeed,LCGRandom]
     
     EndPackage[];



  • Prev by Date: Re: Re: Images in Mathematica
  • Next by Date: Re: Re: Unexpected results
  • Previous by thread: Re: loading packages-followup
  • Next by thread: 2 ticks on a 2D plot