Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: something nice I found today, return multiple values from a function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg113163] Re: something nice I found today, return multiple values from a function
  • From: "Nasser M. Abbasi" <nma at 12000.org>
  • Date: Sat, 16 Oct 2010 13:10:41 -0400 (EDT)
  • References: <i927an$3io$1@smc.vnet.net> <i9a50g$ncb$1@smc.vnet.net>
  • Reply-to: nma at 12000.org

On 10/15/2010 11:02 AM, Andreas wrote:
> Nasser
>
> I've followed this thread for a couple of days and it surprises me
> that it hasn't drawn more discussion.  I think this approach makes
> lots of sense and makes dealing with a wide variety of collections of
> data and results much easier to handle.
>
> I have often found myself "tagging" levels or even elements in a
> output list to try to emulate the same thing, but your idea works much
> better.
>

me too.

> I haven't thought this through completely, but do you see this
> approach having any drawbacks?  Might a struct restrict preclude some
> Mapping operations which one could do on a nested list?
>

Let give a name to this method. How about tagged list?  since when we 
write p["x"]=5  we are like tagging it.   So, lets say the tagged list 
method.

I just been using this tagged lists method just to pass information back 
and forth between functions. And for no other purposes. so far, it seems 
OK, but I did not try too much to find what problems it can cause.

For example, instead of calling a function with 5 or 6 separate 
parameters, I can now call it now with one tagged list, as in:

--------------------------
force[p_] := Module[{}, p["mass"]*p["acc"]]

p["mass"] = 2343.5;
p["acc"] = 25;
force[p]

58587.5
---------------------------

I am not sure how good this method is now,  I am just trying things. May 
be having all the parameters spelled out in the call is better so one 
can see them and do pattern checking on them.

I just sometimes think that having only the 'list' as the main "compound 
data structure" to use can make doing some things a little harder in 
terms of organizing and managing/packaging complex data in a program. 
(oh I forgot, there is a String also).

But at the same time, one can argue that it can also make things 
simpler, since one only have the list to worry about. :)

--Nasser





> I'd like to see this as a package that we could use to define structs
> easily across any notebook.
>
> Very interesting idea.
>
> A.
>
> P.S.  I've posted this through Google Groups but notice that sometimes
> things posted through Google Groups don't seem to appear on the
> original Drexel site.  Anyone else have the trouble?
>



  • Prev by Date: Re: symbolic division of series
  • Next by Date: Re: How to explain these variations in execution speeds?
  • Previous by thread: Re: something nice I found today, return multiple values from a function
  • Next by thread: Re: Why I keep getting error exporting notebooks to HTML?