MathGroup Archive 2006

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

Search the Archive

RE: pattern matching: rules that stop other rules?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg71747] RE: [mg71596] pattern matching: rules that stop other rules?
  • From: "Jose Luis Gomez" <jose.luis.gomez at itesm.mx>
  • Date: Tue, 28 Nov 2006 06:04:01 -0500 (EST)
  • Organization: ITESM

Hello Croddie, try this code:

In[3]:=
ff[x_]:=x+2

In[6]:=
SetAttributes[qwerty1,HoldAll]

In[7]:=
qwerty1[ff[2],ff[3],ff[4]]

Out[7]=
qwerty1[ff[2],ff[3],ff[4]]

In[8]:=
SetAttributes[qwerty2,HoldFirst]

In[9]:=
qwerty2[ff[2],ff[3],ff[4]]

Out[9]=
qwerty2[ff[2],5,6]

In[10]:=
SetAttributes[qwerty3,HoldRest]

In[11]:=
qwerty3[ff[2],ff[3],ff[4]]

Out[11]=
qwerty3[4,ff[3],ff[4]]

 

-----Mensaje original-----
De: croddie at princeton.edu [mailto:croddie at princeton.edu] 
Enviado el: Viernes, 24 de Noviembre de 2006 12:17 a.m.
Para: mathgroup at smc.vnet.net
Asunto: [mg71596] pattern matching: rules that stop other rules?

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: Using Select within Map
  • Next by Date: Re: Descending order
  • Previous by thread: Re: pattern matching: rules that stop other rules?
  • Next by thread: draw vertical cylinder with no surface lines