Re: Curiosity concerning transformation rules for List
- To: mathgroup at smc.vnet.net
- Subject: [mg70925] Re: Curiosity concerning transformation rules for List
- From: "dimitris" <dimmechan at yahoo.com>
- Date: Wed, 1 Nov 2006 03:56:42 -0500 (EST)
- References: <ei4ktg$dbf$1@smc.vnet.net>
Why don't define a rule like below? myrule = {x_, x_} -> {}; lst = Table[Random[Integer, {0, 5}], {20}, {2}] {{1, 4}, {2, 1}, {1, 1}, {4, 3}, {1, 1}, {3, 2}, {5, 1}, {0, 1}, {4, 0}, {3, 4}, {1, 2}, {4, 4}, {3, 0}, {5, 2}, {0, 1},{4, 0}, {5, 1}, {2, 3}, {3, 0}, {5, 2}} lst /. myrule {{1, 4}, {2, 1}, {}, {4, 3}, {}, {3, 2}, {5, 1}, {0, 1}, {4, 0}, {3, 4}, {1, 2}, {}, {3, 0}, {5, 2}, {0, 1}, {4, 0}, {5, 1}, {2, 3}, {3, 0}, {5, 2}} Or use ReplacePart? repEmpty[lis_List] := ReplacePart[lis, {}, Position[lis, {x_, x_}]] repEmpty[lst] {{1, 4}, {2, 1}, {}, {4, 3}, {}, {3, 2}, {5, 1}, {0, 1}, {4, 0}, {3, 4}, {1, 2}, {}, {3, 0}, {5, 2}, {0, 1}, {4, 0}, {5, 1}, {2, 3}, {3, 0}, {5, 2}} Regards Dimitris Andrew Moylan wrote: > Since the List symbol is locked, I am curious about the possibility (or > otherwise) of giving definitions for which the left-hand-side of the > transformation rule contains only the List symbol. Here's an arbitrary, > explicit example: > > Is it possible to make a definition such that: any list of two > identical elements evaluates to the empty list? E.g. {x_, x_} -> {}. > > I can't see any way this transformation rule can be added. It's not > possible to modify the DownValues for List; and there are no > first-level symbols to which an UpValue can be added. Does anyone have > any ideas?