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

MathGroup Archive 2009

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

Search the Archive

Re: problem writing debugging utility function

  • To: mathgroup at
  • Subject: [mg100732] Re: problem writing debugging utility function
  • From: Stonewall Ballard <stoneyb at>
  • Date: Thu, 11 Jun 2009 21:45:29 -0400 (EDT)
  • References: <gvq09k$mqv$> <>

On Jun 5, 4:08 pm, Leonid Shifrin <lsh... at> wrote:
> Stonewall,
> The Function command must obey the general rules of Mathematica evaluatio=
> When we indicate HoldAll as an explicit attribute, this tells Function ho=
> to pass the arguments to its body - to evaluate them first or not. But th=
> HoldAll attribute implicit for Function is always there, and that just
> assures that Function is at all able to do its work, such as variable
> binding and name conflict resolution (Function is a lexical scoping
> construct). Consider an example:

The key here that I didn't understand before is that the implicit
HoldAll attribute of Function applies to the arguments of Function,
not the resultant function. It's probably wrong of me to think that
Function[args, body] creates an object which is then applied to args.
Very lispy thinking.

The attributes argument to Function is needed, then, because there's
no other way to set attributes for subvalues. This is just another
part of the complexity cascade in Mathematica. For example:

In[1]:= Clear[foo, bar]

In[2]:= b = 5

Out[2]= 5

In[3]:= SetAttributes[foo, HoldAll]

In[4]:= foo[b]

Out[4]= foo[b]

In[5]:= bar[b]

Out[5]= bar[5]

In[6]:= foo[b][b]

Out[6]= foo[b][5]

> ...
> To summarize: this internal HoldAll has nothing to do with the arguments
> passed to the function Function[body][arguments]
> (and, by the way, never could, because in expression f[x][y],
> only the processing of <x> is affected by the attributes of <f>), but wit=
> the <body> passed to the function <Function> itself, and is needed for th=
> correct operation of the Function itself. OTOH, correct processing of
> <arguments> according to the attributes given explicitly in the <body> of
> Function is a task of Function's implementation.
> Hope this helps.

Yes, indeed. Thanks.

 - Stoney

  • Prev by Date: Re: Creating Matrix from vectors
  • Next by Date: Re: Re: RandomReal gets stuck
  • Previous by thread: Re: Re: problem writing debugging utility function
  • Next by thread: Re: Re: problem writing debugging utility function