MathGroup Archive 1997

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

Search the Archive

Re: conditional package evaluation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg6186] Re: [mg6170] conditional package evaluation
  • From: Allan Hayes <hay at haystack.demon.co.uk>
  • Date: Thu, 27 Feb 1997 02:53:01 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

murray at math.umass.edu (Murray Eisenberg)
[mg6156] conditional package evaluation
writes

> What are good ways to accomplish the following (in Mathematica 3.0)?
> When a package is loaded, a function in it is going to test the
> value of a certain Global` quantity, CheckMe.  If the value meets 
> the test, then the rest of the package is to be evaluated; other-
> wise it is not.
> The key thing is that I do not want the package's context to be
> created if the test is not met.  (Otherwise, the package's Private
> context could contain the function to make the test.)

Murray:
A variant of your method works:

(* this is the package, not the notebook calling it! *)

If[TrueQ[check],
	BeginPackage["mypackage"`"];
   	f :: usage = "Message for exported function f";

   	Begin["`Private`"];
      	(* other definitions here *)
   	f[x_] := "stuff";
   	End[];
   	Print["OK -- functions defined."];
   	EndPackage[];
   	, (*else*)
   	Print["check failed"];
 ]

Note. It is important to have a semicolon at end of each package  
expression so that new lines are not interpreted as multiplication

Allan Hayes
hay at haystack.demon.co.uk
http://www.haystack.demon.co.uk



  • Prev by Date: Re: Information about non-symbol heads
  • Next by Date: Re: Using subscripts in variable _names_!!!
  • Previous by thread: Re: Information about non-symbol heads
  • Next by thread: Re: Using subscripts in variable _names_!!!