MathGroup Archive 1999

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

Search the Archive

Re: Q: extracting list of arguments of function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16501] Re: Q: extracting list of arguments of function
  • From: dreiss at !SPAMscientificarts.com (David Reiss)
  • Date: Tue, 16 Mar 1999 03:59:50 -0500
  • Organization: EarthLink Network, Inc.
  • References: <7cd7td$o8m@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

In article <7cd7td$o8m at smc.vnet.net>, Jerzy Niesytto
<woland99 at earthlink.net> wrote:

> Let's assume that we want to pass function goo as argument
> to another function foo and extract list of arguments 
> of the function goo:
> foo[fun_] := Module[{argList}, argList = Table[fun[[i]],{i,1,2}] ]
> foo[goo[x,y]];
> 
> This will result in list: 
> {x,y}
> 
> But if goo was defined before eg:
> goo[s_,t_] = s^2 + t^3;
> 
> then we get:
> {x^2,y^3} .....
> 
> Can anybody point me in a right direction here?
> Sorry for such an elementary question...
> 
> JT


One way to do this is to give the function foo the 
attribute HoldAll

In[1]:=

ClearAll[foo];

Attributes[foo]={HoldAll};

foo[fun_[z___]]:={z}


With this you expect the following:

In[2]:= foo[s^2 + t^3]

Out[2]= {s^2, t^3}


And for an arbitrary function h you expect this:

In[3]:= foo[h[a,b,x]]

Out[3]= {a,b,x}


Now if you define goo as

In[4]:= goo[s_,t_] := s^2 + t^3



then the HoldAll attribute causes the argument of foo 
to be looked at in its unevaluated form:

In[5]:= foo[goo[x,y]]

Out[5]= {x,y}


However if Evaluate is explicitly used then the following 
is the result


In[6]:= foo[Evaluate[goo[x,y]]]

Out[6]= {x^2, y^3}


If you don't want this to happen then use the attribute 
HoldAllComplete instead of HoldAll


Cheers,

David

-- 


   
----------------------------------------
 
Scientific Arts:
Creative Services and Consultation 
for the Applied and Pure Sciences
 
  http://www.scientificarts.com

David Reiss 
Email: dreiss at !SPAMscientificarts.com 

----------------------------------------
 


Remove the !SPAM to send email


  • Prev by Date: Re: Modulus Question
  • Next by Date: Re: Problem: Smallest sphere including all 3D points
  • Previous by thread: Re: Q: extracting list of arguments of function
  • Next by thread: Algorithms to calculate square root