Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: HoldFirst question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg65589] Re: HoldFirst question
  • From: albert <awnl at arcor.de>
  • Date: Mon, 10 Apr 2006 02:31:09 -0400 (EDT)
  • References: <e10901$lio$1@smc.vnet.net> <e12tmj$jih$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

> Bear in mind that a HoldFirst function can evaluate its argument - it is
> just that this does not happen automatically. It is easy to write such a
> function yourself:
> 
> SetAttributes[ff,HoldFirst];
> ff[x_]:=(Print[HoldForm[x],"=",x];x)
> 
> Set clearly evaluates the Head of the lhs.

In fact the LHS is evaluated only in certain cases, depending on what the
LHS looks like. LHS that are just symbols are never evaluated, otherwise
there would not be the possibility to redefine "variable" values. More
complicated things like a[[n]] or f[x_] will obviously be at least 
partially evaluated, most probably with  the goal to make the definitions
behave as the user would expect, where it is of course difficult to define
what the user would expect. It is interesting to note e.g. the following:

In[1]:= ClearAll[f,g]

In[2]:= f=g

Out[2]= g

In[3]:= f[x_]=2 x

Out[3]= 2 x

In[4]:= DownValues[f]

Out[4]= {}

In[5]:= DownValues[g]

Out[5]= {HoldPattern[g[x_]] :> 2 x}

In[6]:= f=.

In[7]:= f[2]

Out[7]= f[2]

In[8]:= g[2]

Out[8]= 4

probably surprising but not unreasonable, I wonder if this is all well
documented, though...

albert


  • Prev by Date: Re: GridBox coming back unevaluated
  • Next by Date: Re: Axes with arrowheads !?
  • Previous by thread: Re: HoldFirst question
  • Next by thread: Count Function