6

I found the behavoir have changed. All symbol in System` is kernel funtion(include those your custom funtion)

System`Private`HasAnyCodesQ[Plot]

True


If you run

<<GeneralUtilities`;GeneralUtilities`PrintDefinitions[ShearingMatrix]

You will get the definition of ShearingMatrix.But when you run

<<GeneralUtilities`;GeneralUtilities`PrintDefinitions[UnitStep]

You will get a information that the UnitStep is a kernel function.Can we make a custom function,like KernelFunctionQ, to judge the function in context of System` is a kernel function or not?

yode
  • 26,686
  • 4
  • 62
  • 167
  • 5
    Wouldn't PrintDefinitions[PrintDefinitions] tell you how that's implemented? – ilian Oct 30 '16 at 16:08
  • @ilian Wow,I have not seen your comment before this.I do it just now.Get a chunk code.Maybe it deserve dig.Thanks in advance. – yode Dec 12 '16 at 22:47
  • @yode From my experience HasOwnCodeQ, HasDownCodeQ, HasSubCodeQ, HasUpCodeQ, HowPrintCodeQ will only return true if it's implemented internally. They don't catch OwnValues, DownValue, SubValues, UpValues, or FormatValues. – b3m2a1 Sep 17 '17 at 06:49
  • @b3m2a1 No,see here – yode Sep 17 '17 at 09:43

1 Answers1

6

This is wonderful comment I have to say.I have not think about it before this.As the promption,I get into the page of GeneralUtilities`PrintDefinitions,Then I click Definitions->KernelPlaceholderDefs,I have got this information:

KernelPlaceholderDefs[sym_Symbol] := If[!HasAnyCodesQ[sym],
    {},
    DeleteCases[Null][
        {
            If[HasOwnCodeQ[sym],
                HoldPattern[sym] :> $KernelFunctionPlaceholder
   ],
   If[HasDownCodeQ[sym],
    HoldPattern[sym[___]] :> $KernelFunctionPlaceholder
            ],
            If[HasSubCodeQ[sym],
                HoldPattern[sym[___][___]] :> $KernelFunctionPlaceholder
   ],
   If[HasUpCodeQ[sym],
    HoldPattern[_[___, sym, ___]] :> $KernelFunctionPlaceholder
            ],
            If[HasPrintCodeQ[sym],
                HoldPattern[Format[sym, _]] :> $KernelFunctionPlaceholder
            ]
        }
    ]
];

Attributes[KernelPlaceholderDefs] := {HoldAll};

So the function System`Private`HasAnyCodesQ can judge the function is kernel function or not.Maybe is all of in a local file GeneralUtilities`PackageScope`$KernelFunctionPlaceholder but I don't know how to open it,we can get it all by following code:

kernelFunctions = 
  Quiet[Select[
    ToExpression[CanonicalName[EntityList["WolframLanguageSymbol"]]], 
    System`Private`HasAnyCodesQ]]

{$AssertFunction,Identity,Identity,Abort,AbortProtect,Abs,AbsArg,AbsoluteFileName,AbsoluteTime,AbsoluteTiming,Accumulate,Accuracy,Activate,AcyclicGraphQ,AddTo,AdjacencyList,AdjacencyMatrix,AffineHalfSpace,AffineSpace,AiryAi,AiryAiPrime,AiryBi,AiryBiPrime,AlgebraicIntegerQ,AlgebraicNumber,AlgebraicNumberDenominator,AlgebraicNumberNorm,AlgebraicNumberTrace,AlgebraicUnitQ,AllTrue,...}

A total of $\color{red}{1341}$ kernel function that we can not use GeneralUtilities`PrintDefinitions to get it's definition.And we can see the kernel function is classifid 5 kinds by WR,such as HasOwnCodeQ,HasDownCodeQ,HasSubCodeQ,HasUpCodeQ and HasPrintCodeQ.

yode
  • 26,686
  • 4
  • 62
  • 167