2
$\begingroup$

I want to take a pattern and get a set of matching types. The set of types does not need to be complete, but it needs to satisfy, say, 90% of the cases.

Here's is a (definitely not complete) set of examples:

arg_ -> "Arbitrary"
arg__ -> "Arbitrary sequence"
arg___ -> "Arbitrary blank sequence"
a__Head -> "Head sequence"
a_?IntegerQ -> "Integer"
b_Real -> "Real number"
b_Real?Internal`RealValuedNumericQ -> "Real number"
b_?(Not@*IntegerQ) :> "Arbitrary non-integer"
b_?randomTest ->
 If[MatchQ[randomTest, Symbol], 
  "Arbitrary object passing randomTest", 
  "Indeterminate"
  ]
b_?(Not@*randomTest) :> "Arbitrary object failing randomTest"
OptionsPattern[] -> "Options"
ops : OptionsPattern[] -> "Options"

Being able to spelunk like this will allow me to automatically generate more useful documentation than the trash I generate right now. Even better, we can finally document lots of WRIs trash in a useful way. Bonus points if you can take this and extend it to return a reasonable example a user could execute to get a sense for what the function does.

Hints:

TypeSystem`$AtomPattern

HoldPattern[
 Integer | Real | String | TypeSystem`Boolean | Rational | 
  TypeSystem`Enumeration[__String] | DateObject | TimeObject | 
  TemporalData | Image | 
  Entity[_String] | _Quantity?TypeSystem`ValidQuantityQ | 
  GeoPosition | Graph | Graphics | GeoGraphics | Sound | CloudObject |
   File | URL | Hyperlink | IPAddress | HTTPResponse | HTTPRequest | 
  TypeSystem`AnyType] 
$\endgroup$
  • 1
    $\begingroup$ So "set of matching types" is a list of strings from examples shown above? $\endgroup$ – Kuba Jan 20 at 13:00
  • 1
    $\begingroup$ " Even better, we can finally document lots of WRIs trash in a useful way." If I didn't know better I'd be inclined to downvote for that remark. (Something I rarely do by the way.) $\endgroup$ – Daniel Lichtblau Jan 20 at 15:26
  • $\begingroup$ @DanielLichtblau "WRI's trash" is obviously a reference to highly useful undocumented functions :) But if the line grates I can rewrite it in somewhat more polite language. $\endgroup$ – b3m2a1 Jan 20 at 19:17
  • $\begingroup$ Somehow "useful" and "trash" don't seem to go together (then again, neither do "useful" and "idiot" and yet they have been paired in a colloquialism for some time now). . On a different but related note, we have begun on the Wolfram Function Repository, and some functions from the GeneralUtilities context are being added there. The advantage is they then get better user-visible documentation. $\endgroup$ – Daniel Lichtblau Jan 21 at 15:51
  • 1
    $\begingroup$ What I meant about the repo was not necessarily that you should contribute (though of course we would welcome that) but rather that some of the undocumented "stuff" you have in mind will now be better documented. $\endgroup$ – Daniel Lichtblau Jan 21 at 22:25

Your Answer

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

Browse other questions tagged or ask your own question.