Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

Re: Head logic

  • To: mathgroup at smc.vnet.net
  • Subject: [mg97076] Re: [mg97033] Head logic
  • From: Leonid Shifrin <lshifr at gmail.com>
  • Date: Wed, 4 Mar 2009 07:15:14 -0500 (EST)
  • References: <200903031055.FAA02912@smc.vnet.net>

Hi Carlos,

The reason is that Equal tests for equality by value, not syntactic
equality.
And symbols generally have no value, otherwise they would evaluate to that
value.
On two symbols, for which there is no rule built in the system (or added by
the user)
telling Mathematica  that they should be considered equal, Equal (==) will
return
 unevaluated, which is correct because they are neither necessarily equal
nor necessarily
different.   Use SameQ (===) for syntactic comparison instead of Equal, and
you will get
what you want. Alternatively, use TrueQ[lhs==rhs] - this will force
Mathematica to give
False whenever the result does not evaluate to True.  However, for the case
at hand the
first method (SameQ) seems more appropriate.

Regards,
Leonid

On Tue, Mar 3, 2009 at 1:55 PM, <carlos at colorado.edu> wrote:

> Entering
>
>   ClearAll[r];
>   Head[r]
>   Head[r]!=Symbol
>   Head[r]==Symbol
>
> give Symbol, False and True as expected. But
>
>   Head[r]==Integer
>
> evaluates to Symbol==Integer. Why not False?
> Head[r] is certainly not Integer. Likewise
>
>  r=4;
>  Head[r]==Integer
>  Head[r]!=Symbol
>  Head[r]==Symbol
>
> give True (correct) but  Integer!=Symbol and Integer==Symbol.
> Why not True and False?
>
>


  • Prev by Date: Speed differences between Union, Tally and DeleteDuplicates
  • Next by Date: Re: "Do What I Mean" - a suggestion for improving
  • Previous by thread: Re: Head logic
  • Next by thread: Re: Head logic