|
[Date Index]
[Thread Index]
[Author Index]
Re: HoldFirst confusion
- To: mathgroup at smc.vnet.net
- Subject: [mg65562] Re: HoldFirst confusion
- From: dave at dbaileyconsultancy.co.uk
- Date: Fri, 7 Apr 2006 06:14:41 -0400 (EDT)
- References: <e1095n$lkf$1@smc.vnet.net><e12tqd$jj3$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
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.
>
> On a related note, how can you define and use a downvalue that matches
> g[1+2] without evaluating the 1+2?
>
> --
> Dr Jon D Harrop, Flying Frog Consultancy Ltd.
> http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html
Hello,
The point about HoldFirst is that it suppresses the automatic
evaluation of arguments before a function is called. It is easy to
write a function that has attribute HoldFirst but evaluates its
argument somewhere in its body - all that is necessary is to pass it on
to a deeper function that does not hold the argument!
Regarding the definition of g, the following seems to work:
SetAttributes[g,HoldFirst]
g[1+2]:=Print["xxx"]
David Bailey
http://www.dbaileyconsultancy.co.uk
Prev by Date:
Re: Speed: Inner MUCH slower than dot product??
Next by Date:
Re: Sphere
Previous by thread:
Re: Re: HoldFirst confusion
Next by thread:
Freeing Memory
|