I supose probably yes, but at the end I assume that internally mathematica has to use Set or SetDelayed. Am I right?
Background: I am developing a super simple phraser that takes a code description how objects should work and changes it slightly. Part of the code deals with assignments. They have to be handled in a somewhat special way.
The generic indexing works like
OBJ[id_]@f := f[id]
I noticed that during the assignments Mathematica does not bring OBJ[1]@f to the bitter end, i.e.,f[1]`; for example in
OBJ[1]@f = 1
the left hand side is not resolved to f[1].
I changed how Set and SetDelayed works for fields in objects, and would like to make sure that Mathematica always goes through my definitions:
OBJ /: Set[OBJ[id_]@f, rhs_] := (f[id] = rhs);
OBJ /: SetDelayed[OBJ[id_]@f, rhs_] := (f[id] := rhs);
OBJ /: OBJ[id_][f] := (f[id]);
the first two lines handle the cases like
OBJ[1]@f = 1;
OBJ[2]@f := 2;
while the third line handles the cases like
a = 2 * OBJ[1]@f + 1
of course, a combination is possible:
OBJ[1]@f = OBJ[2]@f + 1;
I am providing the background to the question, which should hopefully put the question in the right context. Hope someone can help.
Set, yes, there are:AppendTo,Increment,AddTo, and probably many others I can't recall ... – Szabolcs Mar 03 '14 at 18:26OJBwhile you're usingOBJelsewhere...Sethas attributeHoldFirst, so that you can make assignments likea = 1even whenahas a value. Try usingEvaluateon the LHS. – rm -rf Mar 03 '14 at 18:39HoldFirstattribute. AnEvaluateshould fix that. In the off-chance that you're using this to emulate some OO like concepts, I would recommend taking a look here: Once more on object orientation in Mathematica: does it have to be so hard? – rm -rf Mar 03 '14 at 18:53