10
$\begingroup$

Seeing the vast scope of science covered by the Wolfram Language (WL) and the large amount of built-in symbols (functions), I am curious to know which built-in symbols are more close to the root of WL, i.e., they are wired deeper in the kernel and are less easily bypassed by tricks.

For example, when assigning UpValues the assignment tag should be at level no deeper than 2. If we make an assignment like

Clear[f,g,tag,fg]
tag/:f[g[tag]]:=fg[tag]

a warning message is displaced as

TagSetDelayed::tagpos: "Tag tag in f[g[tag]] is too deep for an assigned rule to be found."

and the evaluation returns $Failed, because the tag is at level 3.

However, there are some built-in symbols which are not restricted by the level-2-requirement:

list = {HoldPattern, ReleaseHold, Unevaluated, Evaluate,
        Refresh, Activate, IgnoringInactive};
Map[(tag /: f[#[tag]] := #) &, list];

In this code the tag is at level 3, however all assignments can be made successfully without generating error message.

Even at level 4 there is no error message for some combinations:

Map[(tag /: f[#[[1]]@#[[2]]@tag] := #) &, Tuples[list, 2]]

For example, this assignment is successful,

tag /: f[Evaluate@HoldPattern@tag] := tag

It appears that the built-in symbols in list are not considered as normal wrapper. Some of these symbols are also less easily bypassed by using tricks like assigning UpValues, for instance,

tag /: HoldPattern[tag[x_]] := x;
HoldPattern[tag[_]]

which still returns

HoldPattern[tag[_]]

It is reasonable that, out of the thousands of built-in symbols, some of them are more fundamental and the others are built basing on the fundamental ones. Can we find out these fundamental symbols? So we can at least know a bit more about the mystery behind the veil.

$\endgroup$
4
  • 1
    $\begingroup$ Everything listed here that's still in the current version is most likely part of the core. $\endgroup$ – J. M.'s torpor May 8 '15 at 18:28
  • 1
    $\begingroup$ Left hand side of definition is to some extent evaluated, so from your list ReleaseHold, Unevaluated, Evaluate, Refresh and Activate when applied to tag inside f, simply evaluate to tag. Symbols like HoldPattern or IgnoringInactive are also not "more fundamental" they just have special meaning in pattern matching and so are not taken into account when calculating how deep is tag inside pattern. $\endgroup$ – jkuczm May 8 '15 at 19:23
  • 7
    $\begingroup$ One can try to find such symbols with special meaning in pattern matching by testing whether expressions involving those symbols match themselves. Evaluation of Quiet@Select[Names["System`*"], With[{heldExpressions = ToExpression[#, InputForm, Function[sym, {HoldComplete[sym[x]], HoldComplete[sym[x, y]]}, HoldAllComplete]]}, ! MatchQ[heldExpressions, heldExpressions]] &] gives list of 20 such symbols. $\endgroup$ – jkuczm May 8 '15 at 21:19
  • $\begingroup$ @ jkuczm, I see what you mean. When making assignments (with six operators: Set, SetDelayed, TagSet, TagSetDelayed, UpSet and UpSetDelayed), the head then all arguments of lhs are completely evaluated, but the applying of any existing rule for the last step to completely evaluate the partly evaluated lhs (using first UpValues, then DownValues and finally SubValues) is avoided. Thank you for your comments, now my understanding of the evaluation process is strengthened. $\endgroup$ – saturasl May 9 '15 at 21:57

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.