Re: a question about pattern replacements
- To: mathgroup at smc.vnet.net
- Subject: [mg36220] Re: a question about pattern replacements
- From: Alexander Dreyer <dreyer at itwm.fhg.de>
- Date: Tue, 27 Aug 2002 02:07:29 -0400 (EDT)
- Organization: Fraunhofer ITWM
- References: <ak6ope$e9q$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Sidney Cadot wrote: > > Hi all, > > 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? > > Best regards, > > Sidney Cadot Hello, during the Replaceall (/.) Mathematica first evaluate the rule SomeHead[q_] -> Flatten[q] . q is stilla symbol then and will be replaces when /. is used. You can avoid this Problem by using a delayed rule SomeHead[q_] :> Flatten[q] or using thr Rule Somehead->Flatten. Yours, Alexander -- / Alexander Dreyer, Dipl.-Math. - Abteilung Adaptive Systeme \ / Fraunhofer Institut fuer Techno- und Wirtschaftsmathematik (ITWM) \ \ Gottlieb-Daimler-Strasse, Geb. 7^2=49/313 D-67663 Kaiserslautern / \ http://www.itwm.fhg.de Tel.:(0631)205-2851 Fax:(0631)205-4139 /