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

MathGroup Archive 2008

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

Search the Archive

Re: Package File for Different Mathematica Versions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg89976] Re: Package File for Different Mathematica Versions
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Wed, 25 Jun 2008 06:30:24 -0400 (EDT)

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.


  • Prev by Date: Export PDF plot or Save Selection As -- big troubles with Illustrator
  • Next by Date: Re: FindROot and substitutions
  • Previous by thread: Re: Package File for Different Mathematica Versions
  • Next by thread: Re: Re: Package File for Different Mathematica Versions