System`Private`ConstructNoEntry[BesselJ, 0, x]
works fine, and outputs
BesselJ[0, x]
However,
System`Private`ConstructNoEntry[Quantity, 1, "kg"]
enters a recursion and outputs
Why is that?
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityIt 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"]]
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$
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.
BesselJ[0, x]
is also not atomic, why doesn't it suffer recursion problem?
$\endgroup$
Jun 27, 2022 at 1:29
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$
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$
Jun 28, 2022 at 0:56