Re: pattern matching: rules that stop other rules?

• To: mathgroup at smc.vnet.net
• Subject: [mg71644] Re: pattern matching: rules that stop other rules?
• From: "Philipp" <Philipp.M.O at gmail.com>
• Date: Sat, 25 Nov 2006 05:37:31 -0500 (EST)
• References: <ek63v6\$913\$1@smc.vnet.net>

```The If function has HoldRest attribute.

Attributes[If] = {HoldRest, Protected}

Thus, the arguments starting from the second one are unevaluated if If
is unevaluated.

(The term "evaluates to itself" is rather a misnomer, In my opinion,
the "function remains unevaluated" is a more correct way of
conceptualisation.)

You can do the same with your qwerty[] function

In[]:=   Attributes[qwerty] = {HoldRest}
In[]:=   qwerty[p, 1, f[2]]

gives

Out[]=   {HoldRest}
Out[]=   qwerty[p, 1, f[2]]

while

In[]:=   Attributes[qwerty] = {}
In[]:=   qwerty[p, 1, f[2]]

gives

Out[]=   {}
Out[]=   qwerty[p, 1, 0]

Cheers,

Philipp.

croddie at princeton.edu wrote:
> Hello. I've been using Mathamatica for quite a while but without ever
> finding out how the language works fundamentally, which I'm trying to
> do now. I'd be grateful for some help in understanding patterns - it
> seems like a powerful idea to me. There is something I can't work out.
>
> Define a function f [x_]:=0 say
> Now If [ p, 1, f [ 2] ] evaluates to itself. So the rule in the
> definition is not applied to f [ 2 ].
>
> Replace If with some other undefined function, say qwerty, and you get
> qwerty [ p, 1, 0] not surprisingly. And If [ p, 1, f [ 2] ] /. f
> [x_]->0 returns If [ p, 1, 0 ].
>
> Is there a rule associated with If that stops a rule (if that's the
> right expression) from being applied inside it? Can users write such
> rules?
>
> Thanks for any help.

```

• Prev by Date: Re: pattern matching: rules that stop other rules?
• Next by Date: Re: Non-linear Rgression
• Previous by thread: Re: pattern matching: rules that stop other rules?
• Next by thread: RE: pattern matching: rules that stop other rules?