Why does _+_==2_ (or, why is HoldPattern required for sensible matching)?
- To: mathgroup at smc.vnet.net
- Subject: [mg132222] Why does _+_==2_ (or, why is HoldPattern required for sensible matching)?
- From: Alan <alan.isaac at gmail.com>
- Date: Mon, 20 Jan 2014 03:59:45 -0500 (EST)
- Delivered-to: email@example.com
- Delivered-to: firstname.lastname@example.org
- Delivered-to: email@example.com
- Delivered-to: firstname.lastname@example.org
I'm a relatively new user of Mathematica, and the following behavior seems odd to me:
In:= _ + _
Out= 2 _
Use of `Plus` here is just to illustrate a more general "problem with `Blank`. I had expected pattern objects to resist such evaluation. This is possibly related to the fact that I was surprised by the following:
In:= Blank == Blank
Since each Blank can match anything, I find this conceptually to be the wrong behavior. As an example of a counter-intuitive result:
In:= MatchQ[a + b, _ + _]
I understand that I can deal with this problem by using HoldPattern.
In:= MatchQ[a + b, HoldPattern[_ + _]]
So my question is not how to deal with the problem, but rather is a request for an explanation of why the current pattern evaluation behavior is desirable.
Prev by Date:
Re: Compact formulation of array of constraints
Next by Date:
BSplineSurface & BSplineFunction_Extracting Data
Previous by thread:
Re: How to show 1+2+3+ ... = -1/12 using Mathematica's symbols?
Next by thread:
Re: Why does _+_==2_ (or, why is HoldPattern required for