MathGroup Archive 2007

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

Search the Archive

Re: Returning rules from functions inside a package context

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82483] Re: Returning rules from functions inside a package context
  • From: Albert <awnl at arcor.net>
  • Date: Mon, 22 Oct 2007 05:34:04 -0400 (EDT)
  • References: <ff9rjl$4mv$1@smc.vnet.net>

Hi,

as others have pointed out, there are several possibilities to achieve 
what you want. I just wanted to strongly recommend not to use the 
Global`a trick, which will cause all kind of troubles if used in other 
than the most simple cases. In your case you could simply return just 
the number, there seems to be no added value in returning the rule at 
all. Of course if there are more than one parameter in your model, it 
makes sense to return a list of rules, but then I would recommend to 
either use strings with meaningful names as others have mentioned or use 
additional arguments for the symbol names that will be used. This can be 
achieved like this:

BeginPackage["A`"]
f::usage = ""
Begin["`Private`"]

f[a_Symbol] := FindFit[{{0, 0}, {1, 1}}, a x, {a}, x]

End[]

EndPackage[]

The function could then be called like:

f[c]

and returns

{c->1.}

It is now in the responsibility of the caller to make sure that the 
symbols used are not set to a value...

hth,

albert


  • Prev by Date: Re: compute distribution
  • Next by Date: Re: Can Integrate[expr,{x,a,b}] give an incorrect result?
  • Previous by thread: Re: Returning rules from functions inside a package context
  • Next by thread: Re: Returning rules from functions inside a package context