# Decapitating “explicit” and “implicit” heads

This is a follow up to this question.

So far, I named "explicit" heads to those that appear explicitly in the expression. For example, f[x] has an explicit head. I called "implicit" heads to those that are returned by Head but do not appear in the expression. For example, 5 has Integer as implicit head.

In the comments of the original question, rcollyer pointed out that the head of Complex[1,2] is explicit but f@@Complex[1,2] is not "decapitated" because AtomQ@Complex[1, 2] returns True. Then, I came up with the following code:

myAtom /: AtomQ[myAtom[__]] := True
f @@ myAtom[1, 2, 3]
(*f[1,2,3]*)


How does Apply know when the head can be replaced?

According to the documentation of Apply:

Applying to atomic objects that do not have subparts effectively does nothing

Thus, it seems that checking with AtomQ is not enough. One should also check for the existence of parts. For example, Complex[1,2][[1]] returns an error but myAtom[1, 2, 3][[1]] does not. Incidentally, TreeForm[Complex[1, 2]] shows "parts".

Hence the question: Is there a function that makes both checks at once?

Is there a statement similar to myAtom /: AtomQ[myAtom[__]] := True such that
Map[f, {1, {2, myAtom[3]}}, {-1}]

will return {f[1], {f[2], f[myAtom[3]]}}?
• Length[expr]==0 is the test you're looking for, I think, but someone else would have to confirm that it always works. I don't know that much about this. I guessed it because it checks the criteria that you quoted and works for Complex. – C. E. Nov 15 '13 at 6:20
• @Anon: Length[{}]==0 yet f@@{}==f[]. The original question seems now just a convoluted way towards Length[#] == 0 && AtomQ[#] &. – Hector Nov 15 '13 at 10:08
• It is also true that Length@f[] == 0. :/ I don't think it's possible to create a fake atom. I hope someone proves me wrong. – C. E. Nov 15 '13 at 10:28