7
$\begingroup$

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?

$\endgroup$
  • 1
    $\begingroup$ With Trace you will see that Nothing will go though List and disappear. I don't know how to judge this behavior though. $\endgroup$ – Kuba Dec 21 '15 at 14:03
  • $\begingroup$ Query[Nothing] // Normal returns Identity. $\endgroup$ – Karsten 7. Jun 24 '16 at 9:53
5
$\begingroup$

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 &]

$\endgroup$
  • $\begingroup$ Yes, this shows where and how Nothing is ignored during the evaluation. Nice to see! $\endgroup$ – Fred Simons Dec 21 '15 at 14:48
1
$\begingroup$
 Query[Nothing][{1, 2, 3, 4, 5}]
=
  Query[][{1, 2, 3, 4, 5}]
=
  {1, 2, 3, 4, 5}

Hope this helps.

$\endgroup$
  • 2
    $\begingroup$ Since Query[Nothing] gives Query[Nothing] I would argue. $\endgroup$ – Kuba Dec 21 '15 at 14:10
  • $\begingroup$ 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. $\endgroup$ – Fred Simons Dec 21 '15 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.