# Is This a bin Operator Bug?

**URL:** <https://forum.kx.com/t/is-this-a-bin-operator-bug/10205>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [July 29, 2015, 2:30am UTC](https://forum.kx.com/t/is-this-a-bin-operator-bug/10205 "2015-07-29T02:30:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![erik\_friis1](https://avatars.discourse-cdn.com/v4/letter/e/ee59a6/32.png) [@erik\_friis1](https://forum.kx.com/u/erik_friis1)\
**Post date:** [July 29, 2015, 2:30am UTC](https://forum.kx.com/t/is-this-a-bin-operator-bug/10205/1 "2015-07-29T02:30:00Z")

</div>

q)(enlist 0;0;1 2 3) bin 0

1

q)(0;enlist 0;1 2 3) bin 0

0

With the find (?) operator the right operand is properly applied at the leading rank of the left operand, whereas the bin operator does not seem to be applied at the correct rank. &nbsp;Am I missing something?

q)(enlist 0;0;1 2 3) ? 0

0

q)(0;enlist 0;1 2 3) ? 0

0

---

<div class="post-metadata">

**Author:** ![erik\_friis1](https://avatars.discourse-cdn.com/v4/letter/e/ee59a6/32.png) [@erik\_friis1](https://forum.kx.com/u/erik_friis1)\
**Post date:** [July 29, 2015, 6:36am UTC](https://forum.kx.com/t/is-this-a-bin-operator-bug/10205/2 "2015-07-29T06:36:00Z")

</div>

Yes I was missing something that I realized after I posted this: &nbsp;The items in the left operand to the bin operator are not in ascending order. &nbsp;Which brings me to my follow on question – since the operator does not enforce a sorted left operand are the results when it is not undefined?

---

<div class="post-metadata">

**Author:** ![rahul\_asati041](https://avatars.discourse-cdn.com/v4/letter/r/b5e925/32.png) [@rahul\_asati041](https://forum.kx.com/u/rahul_asati041)\
**Post date:** [July 29, 2015, 10:01am UTC](https://forum.kx.com/t/is-this-a-bin-operator-bug/10205/3 "2015-07-29T10:01:00Z")

</div>

Wiki says the same thing: http://code.kx.com/wiki/Reference/bin

The items of the left argument should be sorted ascending although bin does not verify that; if the items are not sorted ascending, the result is undefined. The right argument can be either an atom or simple list of the same type as the left argument

---

<div class="post-metadata">

**Author:** ![erik\_friis1](https://avatars.discourse-cdn.com/v4/letter/e/ee59a6/32.png) [@erik\_friis1](https://forum.kx.com/u/erik_friis1)\
**Post date:** [July 29, 2015, 4:31pm UTC](https://forum.kx.com/t/is-this-a-bin-operator-bug/10205/4 "2015-07-29T16:31:00Z")

</div>

Thanks Rahul! The Wiki should be updated as nested lists (to any level of depth and uniformity) can be specified as both the right and left operands as well. &nbsp;The same rules as the find (?) operator apply regarding how the operator is applied to its right operand. &nbsp;The rules are a bit involved in full, but I have documented the complete behavior in my book.
