MathGroup Archive 2005

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

Search the Archive

Re: rules and lists


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?





  • Prev by Date: Re: Re: [Mathematica 5.1] Bug Report - Two numerical values for a same variable
  • Next by Date: Re: 2D-Plot Colorings
  • Previous by thread: rules and lists
  • Next by thread: Re: rules and lists