Re: Re: HoldFirst confusion
- To: mathgroup at smc.vnet.net
- Subject: [mg65559] Re: [mg65537] Re: HoldFirst confusion
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Fri, 7 Apr 2006 06:14:39 -0400 (EDT)
- References: <e1095n$lkf$1@smc.vnet.net> <200604061053.GAA19559@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On 6 Apr 2006, at 19:53, Jon Harrop wrote:
> Yaroslav Bulatov wrote:
>> The following gives an error
>> f = 5; f[a_] = a
>>
>> Set is HoldFirst, so why does it evaluate it's first argument f[a_]?
>
> Conversely, why do the attributes of Set and SetDelayed indicate
> that they
> hold their first argument when the kernel evaluates it.
the attribute HoldFirst does not actually indicate this. All it
means is that the argument may be evaluated in a special way and not
automatically. This has already been discussed here (see my postings
in 2005 on the subject " Warning from Piecewise") and it is
explained in detail in David Wagner's "Power Programming with
mathematica", page 205.
>
> On a related note, how can you define and use a downvalue that matches
> g[1+2] without evaluating the 1+2?
Do you mean something like this:
In[3]:=
SetAttributes[g,HoldFirst]
In[4]:=
g[1+2]:=3
In[5]:=
g[3]:=5
In[3]:=
SetAttributes[g, HoldFirst]
In[4]:=
g[1 + 2] := 3
In[5]:=
g[3] := 5
In[6]:=
DownValues[g]
Out[6]=
{HoldPattern[g[3]] :> 5, HoldPattern[g[1 + 2]] :> 3}
In[7]:=
g[1+2]
Out[7]=
3
In[8]:=
g[3]
Out[8]=
5
Andrzej Kozlowski
>
> --
> Dr Jon D Harrop, Flying Frog Consultancy Ltd.
> http://www.ffconsultancy.com/products/ocaml_for_scientists/
> chapter1.html
>
- References:
- Re: HoldFirst confusion
- From: Jon Harrop <usenet@jdh30.plus.com>
- Re: HoldFirst confusion