MathGroup Archive 2002

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

Search the Archive

Re: a question about pattern replacements

  • To: mathgroup at smc.vnet.net
  • Subject: [mg36167] Re: [mg36163] a question about pattern replacements
  • From: BobHanlon at aol.com
  • Date: Mon, 26 Aug 2002 04:15:44 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

In a message dated 8/23/02 10:24:31 PM, sidney at jigsaw.nl writes:

>While playing arounf with patterns and substitutions, I came across the
>following behavior which I didn't expect:
>
>z := SomeHead[{{1, 2}, {3, 4}}]
>z /. {SomeHead[q_] -> Flatten[q]}
>
>While this _does_ yield the desired result {1,2,3,4}, Mathematica complains:
>
>Flatten::"normal": Nonatomic expression expected at position 1 in
>Flatten[q].
>
>........as if it is trying to evaluate Flatten[q], with q not bound to
>{{1,2},{3,4}}.
>
>Could anybody explain why this happens?

z:=SomeHead[{{1,2},{3,4}}]

The error is associated with defining the Rule not executing it.  
Note that you get the error with

{SomeHead[q_]->Flatten[q]};

Use RuleDelayed

z/.{SomeHead[q_]:>Flatten[q]}

{1, 2, 3, 4}


Bob Hanlon
Chantilly, VA  USA


  • Prev by Date: Re: Notebook Manipulation
  • Next by Date: Re: NDSolve with integral equation
  • Previous by thread: a question about pattern replacements
  • Next by thread: RE: a question about pattern replacements