Re: Re: New version, new bugs
- To: mathgroup at smc.vnet.net
- Subject: [mg43122] Re: [mg43110] Re: New version, new bugs
- From: Andrzej Kozlowski <andrzej at platon.c.u-tokyo.ac.jp>
- Date: Wed, 13 Aug 2003 07:49:54 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
On Tuesday, August 12, 2003, at 10:43 AM, Maxim wrote: > Also I once again ran into the fact that named and unnamed (Slot[k]) > function parameters behave differently; consider the following > definition: > > In[1]:= > f = #1 /. {x_, y_} :> Refine[Sign[{x, y}], #2] &; > f[{a - b, b - a}, a > b] > > Out[2]= > {1, -1} > > The function f simply returns the signs of the pair of elements under > given > assumptions, but not in this case: > > In[3]:= > f[{y, x}, y > 0 && x < 0] > > Out[3]= > {-1, 1} > > I admit it can be a nuisance but a minor one since to fix it you need just to add half a line: f = #1 /. {x_, y_} :> Refine[Sign[{x, y}], #2] & /. {x -> Unique[x], y -> Unique[y]}; In[3]:= f[{y,x},y>0&&x<0] Out[3]= {1,-1} The flexibility of the Mathematica's pattern matching language means that one can form a huge number of patterns, many of which the designers of the language could not have possibly foreseen. Not surprisingly some of them will not work as one might expect. On the other hand the same flexibility makes it usually easy to find an alternative way to achieve the intended result without the problems encountered encountered with the original approach. It seems to me not unreasonable to view most of the constructions that do not work and which have working alternatives as improperly formed. (The same applies, I think, to your earlier HoldPattern[head][body] construction. Since what it intends to do is exactly equivalent to HoldPattern[head[#]]&[body]-in both cases head is held but body is evaluated - and since the latter approach works without any glitches, it seems to me reasonable to consider the former to be improperly formed and to be avoided). Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/