4
$\begingroup$

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)?

$\endgroup$
6
  • $\begingroup$ Sometimes symbols to which you want to attach DownValues are Protected and/or Locked. $\endgroup$
    – QuantumDot
    Feb 28, 2023 at 19:50
  • $\begingroup$ Does it make sense to ask if OwnValues and SubValues can be converted to DownValues? $\endgroup$
    – Jason B.
    Feb 28, 2023 at 20:22
  • $\begingroup$ Not an answer to the question, but... section 9.7 of the Maple Programming Guide shows an example that essentially uses up-values. $\endgroup$
    – WReach
    Mar 1, 2023 at 2:34
  • $\begingroup$ @JasonB. (*x=.;*)Language`ExtendedFullDefinition[Global`x] gives Language`DefinitionList[x->{OwnValues->{},SubValues->{},UpValues->{},DownValues->{},NValues->{},FormatValues->{},DefaultValues->{},Messages->{},Attributes->{Protected}}]; I think that other values are as important as downvalue. $\endgroup$
    – user688486
    Mar 1, 2023 at 4:16
  • $\begingroup$ @user688486 - I don't know what that printed mess is supposed to add to the discussion. Say I define an OwnValue via x=14. What does it mean to "convert" that to a DownValue? $\endgroup$
    – Jason B.
    Mar 1, 2023 at 13:02

1 Answer 1

2
$\begingroup$

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 enter image description here

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.

$\endgroup$

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.