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.
ReleaseHold,Unevaluated,Evaluate,RefreshandActivatewhen applied totaginsidef, simply evaluate totag. Symbols likeHoldPatternorIgnoringInactiveare also not "more fundamental" they just have special meaning in pattern matching and so are not taken into account when calculating how deep istaginside pattern. – jkuczm May 08 '15 at 19:23Quiet@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. – jkuczm May 08 '15 at 21:19Set,SetDelayed,TagSet,TagSetDelayed,UpSetandUpSetDelayed), 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 firstUpValues, thenDownValuesand finallySubValues) is avoided. Thank you for your comments, now my understanding of the evaluation process is strengthened. – saturasl May 09 '15 at 21:57