MathGroup Archive 1992

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

Search the Archive

Re: Count[{Unevaluated[a]},Unevaluated[a]]

  • To: mathgroup at
  • Subject: Re: Count[{Unevaluated[a]},Unevaluated[a]]
  • From: withoff
  • Date: Wed, 2 Dec 92 14:07:42 CST

>  the above gives - a little bit surprisingly for me - 0.
>  With a third argument: Count[{Unevaluated[a]},Unevaluated[a],{-1}]
>  the result is 1 (as expected). Using On[] one sees that 
>  Count "evaluates" its arguments. Literal instead of Unevaluated gives
>  a similar result.
>  Why does Count do this?

This behavior is a consequence of the way Unevaluated and Literal work.
It is not specific to Count.

Unevaluated is intended for use primarily as the head of a function argument.
When it appears in that position, it is removed prior to evaluating
the function, and without evaluating the argument.  When it appears
in any other position it is usually just another unknown function with
attribute HoldAll.  For example:

In[11]:= SameQ[5, Unevaluated[5]]

Out[11]= True

In[12]:= SameQ[{5}, {Unevaluated[5]}]

Out[12]= False

The reason for similar behavior in Literal is quite different.  Roughly
speaking, Literal is a special version of Hold that is ignored by the
pattern matcher when it appears in something that is being treated
as a pattern.  It is not, however, ignored when it appears in something
that is not being treated as a pattern.  Whether or not an expression
is treated as a pattern depends on context.  For example:

In[15]:= MatchQ[x, Literal[x]]

Out[15]= True

In[16]:= MatchQ[Literal[x], Literal[x]]

Out[16]= False

The second argument in MatchQ is treated as a pattern, so the pattern
Literal[x] matches the expression x.  The pattern Literal[x] does not
match the expression Literal[x], since Literal is not ignored in the

Dave Withoff
withoff at

  • Prev by Date: Vector multiplication??
  • Next by Date: Re: What should Mma be?
  • Previous by thread: Re: Count[{Unevaluated[a]},Unevaluated[a]]
  • Next by thread: calc worksheets--2nd semester