6
$\begingroup$

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?

$\endgroup$
  • 5
    $\begingroup$ Wouldn't PrintDefinitions[PrintDefinitions] tell you how that's implemented? $\endgroup$ – ilian Oct 30 '16 at 16:08
  • $\begingroup$ @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. $\endgroup$ – yode Dec 12 '16 at 22:47
  • $\begingroup$ @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. $\endgroup$ – b3m2a1 Sep 17 '17 at 6:49
  • $\begingroup$ @b3m2a1 No,see here $\endgroup$ – yode Sep 17 '17 at 9:43
6
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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