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

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: [mg82427] Re: Returning rules from functions inside a package context
  • From: "David Park" <djmpark at comcast.net>
  • Date: Sat, 20 Oct 2007 05:47:09 -0400 (EDT)
  • References: <ff9rjl$4mv$1@smc.vnet.net>

When you introduced the symbol 'a' it was in the A`Private` context. That is 
because you used it and thus declared it after the BeginPackage["A`"] and 
Begin["`Private`"] contexts. However, you can put it in the Global` context 
simply by writing Global`a.

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

or

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


-- 
David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/


"Art" <grenander at gmail.com> wrote in message 
news:ff9rjl$4mv$1 at smc.vnet.net...
>
> 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: Returning rules from functions inside a package context
  • Next by Date: Re: a problem about mathematica output
  • Previous by thread: Re: Returning rules from functions inside a package context
  • Next by thread: Re: Returning rules from functions inside a package context