Here's a good reason why I think it should be,
Map[ If[AtomQ@#, #->"is an atom", #->"not an atom"]&
, {"hello",Range@3, # &}
, {-1}
]
During evaluation of In[9]:= Function::slot: Slot[(If[AtomQ[#1],#1->is an atom,#1-> not an atom]&)[1]] (in Slot[(If[AtomQ[#1],#1->is an atom,#1-> not an atom]&)[1]]&) should contain a non-negative integer or string.
Out[9]= {"hello" -> "is an atom",
{1 -> "is an atom", 2 -> "is an atom", 3 -> "is an atom"},
Slot[(If[AtomQ[#1], #1 -> "is an atom", #1 -> " not an atom"] &)[1]] &}
Given that Slot[] is not atomic, to map a function to all atoms in an expression that contains pure functions ends up by messing up their definitions.
Edit 1 - Another Example: I have this list
l1 = {1, Range@3, Point@{2,2}}
and I want to divide all numbers by two. I can do
Map[1/2 #&, l1, {-1}]
{1/2, {1/2, 1, 3/2}, Point[{1, 1}]}
But now if instead of a Point I have a function that creates a Point
l2 = {1, Range@3, Point@{#1,#2}&}
I expect a similar result, where the argument of Point are divided by 2 i.e. Point@{1/2 #1, 1/2 #2}&. But given that Slot[n] is not an atom, that Map divides the index n inside Slot[n] by two, which does not make sense at all
Map[1/2 #&, l2, {-1}]
Function::slot: #((0.5 #1 & )[1]) (in Point[{#((0.5 #1 & )[1]), #((0.5 #1 >&)[2])}] & ) should contain a non-negative integer or string
1&instead of#&, is that result expected? – Kuba Sep 16 '19 at 09:111&instead of #1& does not solve the general problem. See my edit for further examples. – Fortsaint Sep 16 '19 at 09:371&was that it results in possibly an unexpected result from your code, it was not meant to solve anything. I don't have an opinion here, I just said that your example didn't convince me. Btw, take a look at this 198378 thread. Among other things it discusses pros and cons of using atomic expressions. – Kuba Sep 16 '19 at 09:471&, the latter becomes((1*#1)/2 & )[1] &which is not clear what it means, but at least it does not give error insofar it does not mess withSlotargument (the index of Slot) – Fortsaint Sep 16 '19 at 10:131&exhibits issue when you map inside expressions which haveHold*attributes. And...&(Function) isHoldAll. A quick example is#^2& /@ Hold[1,2,3]. So not quite related to the originalSlotproblem but also showing that Map at{-1}result does not need to be 'neat'. – Kuba Sep 16 '19 at 10:29#is notSlot[], butSlot[1]as in the second example, as you can see by# & // FullForm. Interesting, though...I'm not sure atoms are quite what you want to map over here (if you're looking for atoms, you might not want to do it in such a way that keeps them inside their original expression, as in the first example; in the second, you might want to use a more careful/.instead ofMapappropriately.) – thorimur Apr 02 '21 at 20:17