Re: rules and lists
- To: mathgroup at smc.vnet.net
- Subject: [mg54237] Re: [mg54226] rules and lists
- From: "David Park" <djmp at earthlink.net>
- Date: Mon, 14 Feb 2005 00:57:52 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Erich,
You need ReplaceRepeated, //., but then that runs forever. To stop that you
could use something like the following.
list = {1, 2, 3, 3, 1, 2};
list //. {x___, 1, 2, y___} -> {x, f[1, 2, 3], y}
% /. f -> Sequence
{f[1, 2, 3], 3, 3, f[1, 2, 3]}
{1, 2, 3, 3, 3, 1, 2, 3}
David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/
From: Erich Neuwirth [mailto:erich.neuwirth at univie.ac.at]
To: mathgroup at smc.vnet.net
I would like to replace sublists of a list to be replaced by another
list, such that for example the rule
{1,2}->{1,2,3}
wout tranform
{1,2,3,3,1,2} into
{1,2,3,3,3,1,2,3}
Simply gibbin the transformation rule in the form
{x___,1,2,y___}->{x,1,2,3,y}
does not work.
What is the idiom to do what I want?