5
$\begingroup$

The following code returns the first three integer elements of Sqrt[Range[100]]:

Cases[Sqrt[Range[100]], _Integer, 2, 3]
{1, 2, 3}

The following code looks like the preceding code but returns a different result:

Cases[Sqrt[Range[100]], _Integer, {2}, 3]
{2, 3, 5}

As we can see in the following picture, the argument {2} is not documented (it has no braces in the documentation):

enter image description here

What does the second code with {2} instead of 2 mean?

$\endgroup$
2
  • 4
    $\begingroup$ see documentation carefully it is there. $\endgroup$ Aug 3, 2013 at 6:25
  • 1
    $\begingroup$ This is buried in the documentation. I had this same question about Level[] and wouldn't have known to look in the Cases[] documentation. I only found this page with community help. $\endgroup$ Mar 10, 2017 at 1:59

1 Answer 1

9
$\begingroup$

Actually this is documented; you need to look under More Information or Details and Options:

enter image description here

Further, you should realize that levelspec has special meaning in that is it describes a format that is common to a number of functions. Levelspec is described in:

See also: Levels: how do they work?

$\endgroup$
5
  • $\begingroup$ Why is this question different and wasn't closed already? :) $\endgroup$
    – Kuba
    Aug 5, 2013 at 7:31
  • $\begingroup$ @Kuba different from what? $\endgroup$
    – Mr.Wizard
    Aug 5, 2013 at 7:53
  • $\begingroup$ From others which answer is in Details and Options. Obviously (upvotes) this answer is helpful for community but isn't it an example of question which shoud be closed in order to keep repository transparent? Well, I know "should" is not a good word, if there are votes to close it will be. Maybe I should ask: "isn't the policy of SE to close such questions?" $\endgroup$
    – Kuba
    Aug 5, 2013 at 8:02
  • 2
    $\begingroup$ @Kuba I don't understand "keep repository transparent." As far as "SE policy" there is none for such a case; we have added simple mistake / easily found as a custom close reason, but that does not IMHO mean that all questions which are answered by the documentation need to be closed. The documentation isn't always easy to navigate and I hope that this answer serves to group information relating to levelspec in a useful fashion. $\endgroup$
    – Mr.Wizard
    Aug 5, 2013 at 8:06
  • $\begingroup$ I agree than not all need to be closed, but in this case, the answer is almost on top. I do not demand anything, I have also not reason to doubt in your intentions, I just wanted to ask to avoid working against community by voting to close. By "keep repository transparent." I meant, we can rewrite documentation here be such database would be not handy. It is also due to search engine but it is a long story... :) ("Levels: how do...", shoud be easily found by typing "levels" etc. but it isn't due to ":" in the title, check title:levels: is:question and title:levels is:question) $\endgroup$
    – Kuba
    Aug 5, 2013 at 8:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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