MathGroup Archive 2005

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

Search the Archive

Pick function


Hi All,

I have found a strange behavior of the "Pick" function.

Testing data:
------------
In[1]:=
l = {1, a -> b, x, c -> 1, d -> e + f, g + h}

Out[1]:=
{1, a -> b, x, c -> 1, d -> e + f, g + h}

In[2]:=
l2=Table[i,{i,Length[l]}]

Out[2]=
{1,2,3,4,5,6}


Now try to select the "Rules":
-----------------------------
In[3]:=
Cases[l,x:(_->_)]

Out[3]=
{a->b,c->1,d->e+f}

OK, this is what I expected.

but...

Try to use the Pick function:
----------------------------

In[4]:=
sel1=Pick[l,l,_->_]

Out[4]=
{a->b,c->1,d->e+f,0}

In[5]:=
sel2=Pick[l2,l,_->_]

Out[5]=
{2,4,5}


As you can see, the the first command returned 4 items, but the second 
command returned only 3 items (as expected).
I really don't understand why there is the last "0" value in "sel1" list.

I expected, that "Pick[l,l,_->_]" command should return: 
"{a->b,c->1,d->e+f}".


Is here somebody who can explain this strange behavior for me, please?


Zdenek Buk


  • Prev by Date: Re: Questions on Apply function
  • Next by Date: Re: Questions on Apply function
  • Previous by thread: Re: General--tracing the solver
  • Next by thread: Re: Pick function