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: [mg82494] Re: Returning rules from functions inside a package context
  • From: Art <grenander at gmail.com>
  • Date: Mon, 22 Oct 2007 05:39:43 -0400 (EDT)
  • Organization: University of California, Berkeley
  • References: <ff9rjl$4mv$1@smc.vnet.net> <ffedit$bjv$1@smc.vnet.net>

On Sun, 21 Oct 2007 02:29:49 +0000, Vince Virgilio wrote:

> On Oct 19, 4:58 am, Art <grenan... at gmail.com> 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.
> 
> First scope a and x appropriately, as others in this thread have
> advised.
> 
> But then try strings; return the value with the definition f["a"] = 1,
> or if you need rules, perhaps f["a"] = {"a" -> 1}.
> 
> I think it's prudent to keep the symbols to a minimum; they too easily
> introduce difficult dependencies into larger packages.
> 
> Vince Virgilio

Thanks for all the different suggestions. I have a much better idea now, 
though it took me a while.

I am following Jens-Peer's suggestion of defining usage for the each of 
the returned rule symbols. I am guessing that will be the easiest way for 
me to stay out of trouble (and giving Capitalized long names to 
everything). I find, though, that I am parsing the options strings a lot 
with Cases[opts, Rule[x_, y_]-> something] which may be a bad habit.

Art


  • Prev by Date: Re: compute distribution
  • Next by Date: Re: Satellite Visualization!
  • Previous by thread: Re: Returning rules from functions inside a package context
  • Next by thread: a problem about mathematica output