Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #9513 > unrolled thread
| Started by | Andrzej Kozlowski <akozlowski@gmail.com> |
|---|---|
| First post | 2012-04-08 08:17 +0000 |
| Last post | 2012-04-08 08:17 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: evaluate to True? Andrzej Kozlowski <akozlowski@gmail.com> - 2012-04-08 08:17 +0000
| From | Andrzej Kozlowski <akozlowski@gmail.com> |
|---|---|
| Date | 2012-04-08 08:17 +0000 |
| Subject | Re: evaluate to True? |
| Message-ID | <jlrhj7$eon$1@smc.vnet.net> |
Of course there is already a function called "MatchQ". Second, MemberQ
can actually be used for "literal" selection of the kind you seem to be
thinking about.
For example:
MemberQ[{0, 1, 2}, expr_]
True
but
MemberQ[{0, 1, 2}, Verbatim[expr_]]
False
MemberQ[{0, 1, expr_}, Verbatim[expr_]]
True
Thus we can define a "literal" membership checking function as follows:
LiteralMemberQ[expr_, form_] := MemberQ[expr, Verbatim[form]]
Now it behaves the way you expected:
LiteralMemberQ[{0, 1, 2}, 2]
True
LiteralMemberQ[{0, 1, 2}, expr_]
False
and even:
LiteralMemberQ[{0, 1, expr_}, expr_]
True
Andrzej Kozlowski
On 7 Apr 2012, at 11:59, Christoph Lhotka wrote:
> Hello,
>
> yes you are right, I mean MemberQ rather than ModuleQ (please see my
> correction of the post ).
>
> In fact the behaviour is consistent with the information you get for
> MemberQ:
>
> In[1]:= ?MemberQ
>
> "MemberQ[list, form] returns True if an element of list matches form,
> and False otherwise."
>
> In fact the function name is misleading (at least to me): form is never
> a member of list if MemberQ
> returns True. If this would be the case my argumentation (below,
> original post) would bring the
> behaviour of the function in troubles if form is the "expression for
> everything".
>
> The misinterpretation of the function due to the name can be the cause
> of severe bugs as seen
> in message . Maybe a name like MatchQ would be more
> appropriate for future versions
> of Mathematica.
>
> Best,
>
> Christoph
>
>
>
>
> On 04/06/2012 02:38 PM, Bob Hanlon wrote:
>> You mean MemberQ rather than ModuleQ. In MemberQ[list, expr_] a blank
>> (with or without a name for the blank) matches anything.
>>
>> {MemberQ[{a}, _],
>> MemberQ[{"a"}, _],
>> MemberQ[{Indeterminate}, _],
>> MemberQ[{ComplexInfinity}, _],
>> MemberQ[{Plot[x, {x, 0, 1}]}, _]}
>>
>> {True, True, True, True, True}
>>
>>
>> Bob Hanlon
>>
>> On Fri, Apr 6, 2012 at 6:01 AM, Christoph Lhotka
>> <christoph.lhotka@fundp.ac.be> wrote:
>>> Hello,
>>>
>>> I found and interesting subject of discussion in the post
>>>
>>> "Bug in pattern test, or I did something wrong?"
>>>
>>>
>>> I could trace back the problem to an issue with ModuleQ.
>>>
>>> Question: Why does
>>>
>>> In[12]:= ModuleQ[{0,1,2},expr_]
>>>
>>> Out[12]:= True
>>>
>>> evaluate to True?
>>>
>>>
>>> My argumentation is as follows:
>>>
>>> On the one hand there could be a chance that expr_ is 0,1 or 2 but on
>>> the other
>>> hand the probability that expr_ is not 0,1 or 2 is even higher. As a
>>> conclusion it should neither
>>> evaluate to True nor to False.
>>>
>>> In other words: Is there any reason why the expression of everything
>>> (named expr)
>>> is contained in the set {0,1,2} ?
>>>
>>> Best,
>>>
>>> Christoph
>>>
>>
>>
>
>
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web