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: [mg82452] Re: Returning rules from functions inside a package context
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Sat, 20 Oct 2007 05:59:58 -0400 (EDT)
  • References: <ff9rjl$4mv$1@smc.vnet.net>

Hi,

the clean way is to add usage messages to all
the symbols, i.e.,
BeginPackage["A`"]
f::usage = ""
a::usage ="a is the symbol for the slope fitted by f[]."
Begin["`Private`"]

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

End[]

EndPackage[]

The second way is to return a string

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

Begin["`Private`"]

f[] := Module[{fit,a,x},
   fit=FindFit[{{0, 0}, {1, 1}}, a x, {a}, x];
   {"Slope"-> a} /. fit
]

End[]

and the dirty way is

BeginPackage["A`"]
f::usage = ""
a::usage ="a is the symbol for the slope fitted by f[]."
Begin["`Private`"]

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

End[]

Regards
   Jens

Art wrote:
> The following question has been asked and answered in a variety of
> ways in this forum, but I am new to Mathematica and am still not sure what is
> best practice after doing Trace of various trivial statements for the
> past few hours.
> 
> For example, I would like f[] below to return {a->1.}, not
> {A`Private`a->1.}.
> 
> BeginPackage["A`"]
> f::usage = ""
> Begin["`Private`"]
> 
> f[] := FindFit[{{0, 0}, {1, 1}}, a x, {a}, x]
> 
> End[]
> 
> EndPackage[]
> 
> The use of Rule[] in different scoping constructs is confusing.
> 
> Thanks.
> 
> 


  • Prev by Date: Re: a problem about mathematica output
  • Next by Date: Re: Re: Integrate question
  • Previous by thread: Re: Returning rules from functions inside a package context
  • Next by thread: Re: Returning rules from functions inside a package context