As this post has discussed, UpValues
are certainly useful, and as this post has discussed, g /: f[g[x_]] := h[x]
is not equivalent to f[g[x_]] := h[x]
, but that's not the point. It appears that other languages don't provide the alleged UpValues
in general.
So, my question is: can UpValues
and other *Values
all always be converted to DownValues
(rather than asking for those distinctions)? And if not, does this mean that one can never implement the same functionalities in MMA's competitive products (like Maple and Mathics)?
1 Answer
This is not an answer but a comment with image.
Certainly the UpValues
can be converted to DownValues
and the SubValues
can be curried to DownValues
manually, but then we mess up the bindings of symbols.
Before embracing associations I usually used the DownValues
, UpValues
and SubValues
to store data.
Although there is no native OOP in Mathematica, we can treat certain symbols e.g. class
as class like,
masterOf[class]^=...
servantOf[class]^=...
isProtected[class]^=...
class["some instance"]=...
...
For example, the GR packages xAct`*
use this method to manage relations between geometric objects
So UpValues
is quite useful to make the dependencies of symbols more structured.
But with the more powerful Association
and the interface Dataset
, we can free ourselves from the cumbersome symbol management.
DownValues
areProtected
and/orLocked
. $\endgroup$OwnValues
andSubValues
can be converted toDownValues
? $\endgroup$(*x=.;*)Language`ExtendedFullDefinition[Global`x]
givesLanguage`DefinitionList[x->{OwnValues->{},SubValues->{},UpValues->{},DownValues->{},NValues->{},FormatValues->{},DefaultValues->{},Messages->{},Attributes->{Protected}}]
; I think that other values are as important as downvalue. $\endgroup$OwnValue
viax=14
. What does it mean to "convert" that to aDownValue
? $\endgroup$