Re: programming in Mathmatica
- To: mathgroup at smc.vnet.net
- Subject: [mg13468] Re: programming in Mathmatica
- From: "Allan Hayes" <hay at haystack.demon.cc.uk>
- Date: Sun, 26 Jul 1998 02:33:31 -0400
- References: <6p6rtm$5me@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
John M. Dlugosz wrote in message <6p6rtm$5me at smc.vnet.net>...
>Consider this function:
>
>(*1*) ackPrim[m_Integer, 0] := (
>(*2*) ++counter;
>(*3*) {result_,rc_ } -> cAck[m-1,1]; (*4*) { result, rc+1 }
>(*5*) );
>
>
>The function cAck returns a list of two items. In Perl I write:
> my ($result, $rc) = cAck ($m-1, 1);
John
Set and SetDelayed are listable, for example
{f[x_/;x>4],{g[y_],z}} = {1,{2/;y>3,{3}}};
The assingments stored are
?f g z
Global`f
f[x_ /; x > 4] = 1
Global`g
g[y_] = 2 /; y > 3
Global`z
z = {3}
Similarly with SetDelayed (:=)
>Next, you see I'm using a list of two values. For more complex
>programs, such "structures" represented as lists would get a little
>awkward. I can imagine using access functions to pull the correct
>member of a list, so I get the benifit of named structure members, and
>even creating an operator for that which works similarly to the "dot"
>in Algol-decendent languages. So, I assume people have done this
>already and there is a standard idiom in circulation for it. What is
>it, so I don't have to re-invent my own?
>
>=> What is the standard practice for using what other languages do with
>"structures"?
Could you give some Mathematica examples of what you want to do please.
Allan
------------------------------------------------------------- Allan
Hayes
Training and Consulting
Leicester UK
http://www.haystack.demon.co.uk
hay at haystack.demon.co.uk
voice: +44 (0)116 271 4198
fax: +44(0)116 271 8642