Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

Re: loading autosaved package using Needs[]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg95120] Re: [mg95083] loading autosaved package using Needs[]
  • From: "David Annetts" <davidannetts at aapt.net.au>
  • Date: Wed, 7 Jan 2009 04:07:10 -0500 (EST)
  • References: <200901060909.EAA25587@smc.vnet.net>

 Hi Mitch,

<snippage>
> 	Needs["phd_thesis_common.m"]
> 	Needs::cxt: Invalid context specified at position 1 in 
> Needs[phd_thesis_common.m]. A context must consist of valid 
> symbol names separated by and ending with `. >>
> 
> any help/suggestions appreciated.

When you usually load WRI-supplied packages, you don't specify the ".m"
extension, so why are you doing so here?

If you've defined your package using 

	BeginPackage["packagename`"]

then as long as your working directory in in your search path, you can load
your package using 

	Needs["packagename`"]

Note the trailing "`" character & no ".m" extension.

There's a tutorial at tutorial/SettingUpMathematicaPackages in the
documentation but a very simple example follows.  Save the notebook as
test.nb after adjusting the directory, and don't evaluate the init cells 

(* cell 1 *)
SetDirectory["d:/Tmpfiles"];

(* cell 2: set these as init. cells *)
BeginPackage["test`"];
Working::usage = "Working[] should print Hello World";
Begin["`Private`"];
Working[] := Print["Hello World"];
End[]; (* PRivate*)
EndPackage[];
(* end init cells *)

(* cell 3 *)
Quit[] (* don't use the package we just created -- force it to load from
disk *)

(* cell 4: don't evaluate init cells !*)
SetDirectory["d:/Tmpfiles"];
Needs["test`"]
Working[]

Regards,

Dave.




  • Prev by Date: Manipulate, Export, .avi, forward run without the slider in the
  • Next by Date: Re: Please answer to my questions,thank you.
  • Previous by thread: loading autosaved package using Needs[]
  • Next by thread: Re: loading autosaved package using Needs[]