7

In Mathematica 10, Nothing is defined as to automaticaly disappear when used in a list or in an association, and moreover with the property that it returns Nothing when called with any number of arguments.

Consider the following Query:

(Query[f][{1, 2, 3, 4, 5}]

(* f[{1, 2, 3, 4, 5}] *)

Hence, when we use Nothing instead of f, I expected the result to be Nothing[{1,2,3,4,5}], wich evaluates to Nothing. However:

Query[Nothing][{1, 2, 3, 4, 5}]

(* {1, 2, 3, 4, 5} *)

The expression Nothing cannot be used as a part specification, but here it behaves like the part specification All. So is Nothing All in Queries?

Fred Simons
  • 10,181
  • 18
  • 49

2 Answers2

5

You can use Query[Nothing][{1, 2, 3}] // Trace to catch a problematic moment:

Dataset`Query`PackagePrivate`compile0[
   {Nothing}, 
   OptionValue[ Query, {}, {FailureAction, PartBehavior, MissingBehavior}]
]

and subsequent evaluation of {Nothing} to {}, from now on, there will be no trace of Nothing and Identity is called:

 Dataset`Query`PackagePrivate`compile0[{}, {"Abort", Automatic, Automatic}]
Dataset`OverrideMissing[GeneralUtilities`Checked[Identity, Identity]]

while ...Checked[Nothing, Identity] could work.

I don't know if that's expected or not.

p.s. if you want to use it as an operator, use Query[Nothing &]

Kuba
  • 136,707
  • 13
  • 279
  • 740
1
 Query[Nothing][{1, 2, 3, 4, 5}]
=
  Query[][{1, 2, 3, 4, 5}]
=
  {1, 2, 3, 4, 5}

Hope this helps.

Edmund
  • 42,267
  • 3
  • 51
  • 143
  • 2
    Since Query[Nothing] gives Query[Nothing] I would argue. – Kuba Dec 21 '15 at 14:10
  • As @Kuba has shown, Nothing does not disappear in Query. Nevertheless, I think you are close to an explanation. I tested the following three cases: Query[1,All,1][{{1}}], Query[1, Nothing,1][{{1}}], Query[1, 1][{{1}}]. It gives me the impression that Nothing is simply ignored during the evaluation. That also answers my question. Nothing is not All. – Fred Simons Dec 21 '15 at 14:29