It is possible to implement OOP in Mathematica using something like
and it's convenient to extract value from the object by setting:
but how to write a convenient value assignment so that this form of set action is valid?
My (obviously unsuccessful) attempts:
c /: Set[o : (c[a_])[b_], val_] := (o=c[ReplacePart[a,Key[b]->val]])
This obviously won't work as the
HoldFirst attribute of
Set prevent the pattern matching of
but without it:
Set[o_[b_], val_]/;Head[o]==c := (o=c[ReplacePart[a,Key[b]->val]])
Protected and simply matching all
o_[b_] type and then filter by
Head is simply so inefficient.