MathGroup Archive 2012

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

Search the Archive

is Head[] part of the expression?

  • To: mathgroup at
  • Subject: [mg126880] is Head[] part of the expression?
  • From: "Nasser M. Abbasi" <nma at>
  • Date: Fri, 15 Jun 2012 03:41:24 -0400 (EDT)
  • Delivered-to:
  • Reply-to: nma at

I am now in a state of little confusion about when Head[]
of a list (the value at index 0) is 'looked' at when
passing a list to a function to process the list.

For example, below I have a list, and then Position[]
is passed this list to find the nonzero elements in
the list.

Depending on the test for zero used, different
results show up. Sometime the Head[] of the list
is examined (because I get zero index) and sometime
it is not.

So, my question, what is the rule-of-thumb on this?
I am making a cheat sheet for Mathematica, and
wanted to make a simple rules to remember.

-- case 1 -----

Out[68]= {{1},{3}}   (*what I expected*)

--- case 2 --------------------

Out[69]= {{0},{1},{3}}

----- case 3 ---------------------

Out[70]= {{0},{1},{3},{}}

---- case 4--------------
Position[v, x_ /; Not[SameQ[x, 0]], 2]

Out[71]= {{0},{1},{3}}



  • Prev by Date: Re: modulo solving lacking domain?
  • Next by Date: Re: Varying a constant in an ODE to Manipulate solution
  • Previous by thread: Re: fyi, small note on using Mathematica for object based programming
  • Next by thread: Re: part of the expression?