Message Boards Message Boards

0
|
3415 Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

[Solved] Apply pattern and rule correctly

Posted 4 years ago

Hi all, I'm just beginning to learn about patterns and rules. How would I have to write the following rule, so that the enclosing list does not get processed by it? (Meaning: How do I get rid of the first "x"?)

{1, 2, 3, a, b, c} /. {i_Integer -> i*2, s_Symbol -> x}
x[2, 4, 6, x, x, x]

Thank you very much!

POSTED BY: Timo Kuchheuser
4 Replies
Posted 4 years ago

Try

Replace[{1, 2, 3, a, b, c}, {i_Integer -> i*2, s_ -> x}, {1}]

which gives me

{2,4,6,x,x,x}
POSTED BY: Bill Nelson

That did the trick. Thank you!

POSTED BY: Timo Kuchheuser

Hmm, that doesn't work, I'm afraid.

POSTED BY: Timo Kuchheuser
Posted 4 years ago
{1, 2, 3, a, b, c} /. {i_Integer -> i*2, 
  s_Symbol /; Head[s] != List -> x}
POSTED BY: Michael Helmle
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract