System`Private`ConstructNoEntry[BesselJ, 0, x]

works fine, and outputs

BesselJ[0, x]


System`Private`ConstructNoEntry[Quantity, 1, "kg"]

enters a recursion and outputs

$RecursionLimit::reclim2: Recursion depth of 1024 exceeded during evaluation of QuantityUnitsPrivateiu:IndependentUnit[_String].

Why is that?


2 Answers 2


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:

System`Private`ConstructNoEntry[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 System`Private`SetNoEntry after evaluation of Quantity[1, "kg"]:

System`Private`SetNoEntry[Quantity[1, "kg"]]
  • $\begingroup$ That is interesting. But I do not see why Quantity tries to resolve "kg" to "Kilograms" will enter a recursion. $\endgroup$
    – matheorem
    Commented Jun 27, 2022 at 1:31
  • 1
    $\begingroup$ @matheorem You can Trace what actually happens. Usage of System`Private`ConstructNoEntry 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). $\endgroup$ Commented Jun 27, 2022 at 1:49

"Why does System`Private`ConstructNoEntry[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.

  • 1
    $\begingroup$ Hi, Jason B. Thank you for answering. But BesselJ[0, x] is also not atomic, why doesn't it suffer recursion problem? $\endgroup$
    – matheorem
    Commented Jun 27, 2022 at 1:29
  • $\begingroup$ @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 $\endgroup$
    – Jason B.
    Commented Jun 27, 2022 at 15:34
  • $\begingroup$ Hi, Jason B. Thank you very much for comment : ) I understand your point. But I do not think System`Private`ConstructNoEntry[Quantity, 1, "kg"] is ridiculous thing. As far as I know, System`Private`ConstructNoEntry is used for making any Head atomic, why not Quantity. Anyway, as point out by Alexey Popkov, System`Private`SetNoEntry works for Quantity, so I would think there is some buggy things in System`Private`ConstructNoEntry that make it fail for Quantity. Finally, since these are undocumented functions, I agree it may not be a great deal :) $\endgroup$
    – matheorem
    Commented Jun 28, 2022 at 0:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.