# Why does SystemPrivateConstructNoEntry[Quantity, 1, "kg"] enter a Recursion?

SystemPrivateConstructNoEntry[BesselJ, 0, x]


works fine, and outputs

BesselJ[0, x]


However,

SystemPrivateConstructNoEntry[Quantity, 1, "kg"]


enters a recursion and outputs

Why is that?

It is because KnownUnitQ["kg"] returns False, and hence Quantity tries to resolve "kg" to "Kilograms". To avoid this, use only known units in the input:

SystemPrivateConstructNoEntry[Quantity, 1, "Kilograms"]


To get the right form for the input of Quantity, apply InputForm:

Quantity[1, "kg"] // InputForm

Quantity[1, "Kilograms"]


Alternatively, just apply SystemPrivateSetNoEntry after evaluation of Quantity[1, "kg"]:

SystemPrivateSetNoEntry[Quantity[1, "kg"]]

• That is interesting. But I do not see why Quantity tries to resolve "kg" to "Kilograms" will enter a recursion. Jun 27, 2022 at 1:31
• @matheorem You can Trace what actually happens. Usage of SystemPrivateConstructNoEntry is a kind of a hack which allows to construct an atomic object representing an expression which normally shouldn't be atomic. This breaks things like part extraction, applying replacement rules via ReplaceAll, etc. (which can be used by Quantity internally). Jun 27, 2022 at 1:49

"Why does SystemPrivateConstructNoEntry[Quantity, 1, "kg"] enter a Recursion"? Because the developers of the Quantity function have every expectation that a Quantity object will not be atomic, and write the code accordingly. This is a reasonable assumption for them to make.

Seems like a case of GIGO.

• Hi, Jason B. Thank you for answering. But BesselJ[0, x] is also not atomic, why doesn't it suffer recursion problem? Jun 27, 2022 at 1:29
• @matheorem - I responded a couple times and deleted the response, will try again. Whether BesselJ gives a recursion error when used incorrectly is not an interesting question. My point was that if you do ridiculous things like in the OP here, don't be surprised when things blow up in your face. Try Block[{Quiet=Quit}, Plot[x, {x, -3, 3}]] if you want more examples of garbage-in garbage-out Jun 27, 2022 at 15:34
• Hi, Jason B. Thank you very much for comment : ) I understand your point. But I do not think SystemPrivateConstructNoEntry[Quantity, 1, "kg"] is ridiculous thing. As far as I know, SystemPrivateConstructNoEntry is used for making any Head atomic, why not Quantity. Anyway, as point out by Alexey Popkov, SystemPrivateSetNoEntry works for Quantity, so I would think there is some buggy things in SystemPrivateConstructNoEntry that make it fail for Quantity. Finally, since these are undocumented functions, I agree it may not be a great deal :) Jun 28, 2022 at 0:56