MathGroup Archive 2004

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

Search the Archive

Re: Returning rules ...

  • To: mathgroup at smc.vnet.net
  • Subject: [mg47602] Re: [mg47470] Returning rules ...
  • From: Yasvir Tesiram <Yasvir-Tesiram at omrf.ouhsc.edu>
  • Date: Sat, 17 Apr 2004 02:31:42 -0400 (EDT)
  • References: <200404131026.GAA10868@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

G'day,
I may have missed return threads to this, but wouldn't MyFunction[arg] 
return the list of results with Value1->val.

e.g.

dosomething[num_] := Module[{mysum, myproduct},

     mysum = Apply[Plus, num];
     myproduct = Apply[Times, num];
     results = {sum -> mysum, product -> myproduct}

     ]


test = dosomething[Table[Random[], {20}]]

({sum -> 10.522348737092829`, product -> 1.6096346164220132`*^-8}

sum /. test

10.5223


As far as I understand, mysum, myproduct and results are local to 
dosomething.

I hope this is what you were after, or perhaps a more specific example 
would help.

Cheers
Yas



On Apr 13, 2004, at 8:26 PM, David.Annetts at csiro.au wrote:

> Hi,
>
> We are familiar with functions such as Solve[] that return results as a
> series of rules.  My question is how to define a Module that does
> essentially the same thing.  For example, I'd like to be able to do
> 	test = MyFunction[args];
>
> where MyFunction[args_] := Module[
> 	{},
> 	...
> 	Return[{...}];
> 	];,
>
> and have test returned as the list
> 	test = {
> 		Value1 -> val1,
> 		Value2 -> val2, ...}
>
> Can anyone suggest a straightforward means of accomplishing this 
> without
> resorting to Global` variables?  Sample code (eg
> Statistics`LinearRegression` that returns results in the form I've
> described above) has not proved particularly helpful.
>
> Many thanks,
>
> Dave.
> ==========================================
>   Dr. David Annetts
>   EM Modelling Analyst
>   CSIRO DEM            Tel: +612 9490 5416
>   North Ryde           Fax: +612 9490 5467
>   Australia         David.Annetts at csiro.au
> ===========================================


  • Prev by Date: A simple integral
  • Next by Date: Re: Critical memory leak with J/Link
  • Previous by thread: Returning rules ...
  • Next by thread: Re: Returning rules ...