MathGroup Archive 2008

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

Search the Archive

Re: Re: Package File for Different Mathematica Versions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg90002] Re: [mg89976] Re: Package File for Different Mathematica Versions
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Thu, 26 Jun 2008 04:41:54 -0400 (EDT)
  • Organization: Mathematics & Statistics, Univ. of Mass./Amherst
  • References: <200806251030.GAA18948@smc.vnet.net>
  • Reply-to: murray at math.umass.edu

And you might make the handling of the conditional simpler by organizing 
things like this:

   myfunc5[x_]:= x^2;
   myfunc6[x_]:= 2x;
   myfunc[x_]:=If[$VersionNumber>=6, myfunc5[x],myfunc6[x]]

That way, you can keep what's inside the If expression much shorter and 
therefore easier to maintain.

Bill Rowe wrote:
> On 6/24/08 at 3:29 AM, acbev at lanl.gov (Andrew Beveridge) wrote:
> 
>> I am writing a package file for Mathematica. I have two versions of
>> Mathematica targeted: 5.2 and 6.0.x.
> 
>> It would be nice to use some of the improvements in Version 6.0.x
>> without losing backwards compatibility with Version 5.2.
> 
>> I imagine one way to implement this would be the following:
> 
>> If $VersionNumber >= 6 then ... else ...
> 
>> However, I would prefer not to put a bunch of If statements into my
>> code; multiple lines would have to be modified. Is there are more
>> elegant way around this problem? Can a function be defined for a
>> particular versions of Mathematica in a package file?
> 
> Yes, a function can be defined for a particular version of
> Mathematica. You could have a construct like
> 
> If[$VersionNumber >=6,
>     myfunc[x_]:=x^2,
>     myfunc[x_]:=2 x];
> 
> 
> 
> That is you can put the definitions for functions inside an If
> construct. And if you all the code for version 5 separate from
> all of the code for version 6, you should be able use one If
> construct. In essence what you are doing is making your function
> definitions for version 5 part of a compound expression and
> function definitions for version 6 part of another compound
> expression. Then the If construct determines which compound
> expression is evaluated which ensures the correct definitions
> are used.
> 
> For awhile, I was using this type of construct in my init.m file
> so that I could keep both versions 5 and 6 running with the same
> init.m file quite successfully. I've since edited this out since
> I no longer use version 5.x.
> 

-- 
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305


  • Prev by Date: Problem with NMaximize
  • Next by Date: Re: Piecewise and multiple values
  • Previous by thread: Re: Package File for Different Mathematica Versions
  • Next by thread: Re: Package File for Different Mathematica Versions