MathGroup Archive 2006

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

Search the Archive

Re: HoldAll

  • To: mathgroup at
  • Subject: [mg66555] Re: [mg66550] HoldAll
  • From: Andrzej Kozlowski <akoz at>
  • Date: Sat, 20 May 2006 04:46:49 -0400 (EDT)
  • References: <>
  • Sender: owner-wri-mathgroup at

On 19 May 2006, at 16:40, umrakmm at wrote:

> Hello to everyone
> Quick question with regards to why the HoldAll attribute no longer  
> works once
> you define the function.  For example, before the definition, it  
> serves the
> purpose it was meant to serve:
> Input
> Clear[ff]
> SetAttributes[ff, HoldAll]
> ff[1, 2, 3 + 4]
> Output
> ff[1, 2, 3 + 4]
> But once I actually assign the "functional guts", it doesn't do  
> what it did
> above:
> ff[x_, y_, z_] := x + y + z;
> ff[1, 2, 3 + 4]
> 10
> Why?
> Thanks to all
> MR

I think you are misunderstanding what HoldAll does. Functions without  
this attribute (or other similar ones, like HoldFirst, HoldRest etc)  
first pre-evaluate the arguments, then insert them into the body of  
the function and then evaluate the body of the function.  Functions  
with the HoldAll attribute do not pre-evaluate their arguments, but  
insert them into the body and evaluate it as part of the body. So  
both of your examples behave in exactly he same way, except that as  
there is no "function body" in the former case "evaluating the body"  
does not amount to anything. You can perhaps see this more clearly by  
looking at the following example:


SetAttributes[ff, HoldFirst]




The function ff has the HoldFirst attribute so the argument 1+2 was  
not pre-evaluated. However, inside the body of the function it was  
evaluated, which is why you got the Hold[1+2] and 3 as the first two  
elements in the output. On the other hand since ff evaluates it's  
second argument it was evaluated before being inserted into the  
function body, so you got Hold[7] and 7 in the output.

Andrzej Kozlowski
Tokyo, Japan

  • References:
    • HoldAll
      • From:
  • Prev by Date: Re: problem for "Fit"
  • Next by Date: Re: Exporting Graphics to .eps
  • Previous by thread: HoldAll
  • Next by thread: Re: HoldAll