       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:=
SetAttributes[g,HoldFirst]

In:=
g[1+2]:=3

In:=
g:=5

In:=
SetAttributes[g, HoldFirst]

In:=
g[1 + 2] := 3

In:=
g := 5

In:=
DownValues[g]

Out=
{HoldPattern[g] :> 5, HoldPattern[g[1 + 2]] :> 3}

In:=
g[1+2]

Out=
3

In:=
g

Out=
5

Andrzej Kozlowski

>
> --
> Dr Jon D Harrop, Flying Frog Consultancy Ltd.
> http://www.ffconsultancy.com/products/ocaml_for_scientists/
> chapter1.html
>

```

• Prev by Date: Re: Sphere
• Next by Date: Re: Re: HoldFirst confusion
• Previous by thread: Re: HoldFirst confusion
• Next by thread: Re: Re: HoldFirst confusion