MathGroup Archive 2011

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

Search the Archive

Re: Apply a rule to an expression only once

  • To: mathgroup at smc.vnet.net
  • Subject: [mg116385] Re: Apply a rule to an expression only once
  • From: Fred Simons <f.h.simons at tue.nl>
  • Date: Sat, 12 Feb 2011 05:21:39 -0500 (EST)
  • References: <201102110920.EAA08165@smc.vnet.net>

I tried to answer your question in a slightly simpler situation: I have 
a list of positive integers, and I want to define a rule that, each time 
when it is called, replaces only one of the integers of a list with 0. 
The following seems to work:

In[1]:= rule:= With[{z=Unique[z]} , z=True;  n_Integer /;z :>If[z, 
z=False;0, n]];
{1,2,3}/. rule
{4,5,6} /.rule

Out[2]= {0,2,3}

Out[3]= {0,5,6}

Regards,

Fred Simons
Eindhoven University of Technology


  • Prev by Date: solution of equation
  • Next by Date: Re: list manipulation
  • Previous by thread: Re: Apply a rule to an expression only once
  • Next by thread: Re: Apply a rule to an expression only once