# How to judge the function is kernel function or not in program method?

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

SystemPrivateHasAnyCodesQ[Plot]

True

If you run

<<GeneralUtilities;GeneralUtilitiesPrintDefinitions[ShearingMatrix]


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

<<GeneralUtilities;GeneralUtilitiesPrintDefinitions[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?

• 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 6:49
• @b3m2a1 No,see here – yode Sep 17 '17 at 9:43

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 GeneralUtilitiesPrintDefinitions,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 SystemPrivateHasAnyCodesQ can judge the function is kernel function or not.Maybe is all of in a local file GeneralUtilitiesPackageScope$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"]]],
SystemPrivateHasAnyCodesQ]]


{$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 GeneralUtilitiesPrintDefinitions 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.