MathGroup Archive 2006

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

Search the Archive

Re: HoldAll

  • To: mathgroup at smc.vnet.net
  • Subject: [mg66574] Re: [mg66550] HoldAll
  • From: "Igor C. Antonio" <igora at wolf-ram.com>
  • Date: Sat, 20 May 2006 04:47:55 -0400 (EDT)
  • Organization: Wolfram Research, Inc.
  • References: <200605190740.DAA12901@smc.vnet.net>
  • Reply-to: igora at wolf-ram.com
  • Sender: owner-wri-mathgroup at wolfram.com

MR,

HoldAll doesn't mean it will hold the values forever.  It will not evaluated the 
arguments until after they've been passed into the function.

Example:

In[1]:= f[{a_ + b_}] := a

In[2]:= f[{1 + 2}]

Out[2]= f[{3}]

In the code above, Mathematica first evaluated {1+2}, then passed it as an 
argument to the function f.  Since there's no definition of f to handle f[{x_}], 
it returned unevaluated.

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

In[4]:= g[{a_ + b_}] := a + b

In[5]:= g[{1 + 2}]

Out[5]= 3

With HoldAll, {1+2} was passed to the function as it is.  It matched the pattern 
and then once "inside" the function, then it was evaluated normally.

If you don't want something to evaluate until you want to, use Hold.

Igor




umrakmm at cc.umanitoba.ca 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
> 
> -------------------------------------------------
> This mail sent through IMP: http://horde.org/imp/


-- 

--
Igor C. Antonio
Wolfram Research, Inc.
http://www.wolfram.com

To email me personally, remove the dash.


  • References:
    • HoldAll
      • From: umrakmm@cc.umanitoba.ca
  • Prev by Date: Re: derivative of cubic spline
  • Next by Date: Re: (Newbie question): New types of numbers
  • Previous by thread: Re: HoldAll
  • Next by thread: Re: HoldAll