Tag Info

Hot answers tagged

17

At the risk of repeating myself, I would like to stress that one has to be critical towards the superficial flexibility offered by Mathematica, when (particularly mutable) data structures are concerned. Using mutable data structures assumes a programming style for which Mathematica is not optimized. It can emulate it, yes, and we have seen a number of such ...


17

It is probably debatable to what extent it has built-in object oriented features. In any case, this answer is not intended to lead you to try to emulate object oriented programming, which is in general a bad idea. (see @Leonid 's answer) However, it is not debatable that Mathematica is tremendously flexible (as to style and notation at least, the evaluation ...


4

I don't know a way with subvalues, but you can use Module to create objects without explicit identifier in makeObj: makeObj[] := Module[{field = 0}, Switch[#, "increase", field++; #0, "field", field]&] (Note that I slightly changed your "increase" function to return #0, that is, "self", so I can chain ...


4

Well, one obvious idea would be to build on the struct implementation by Bob Beretta. You would have to add information about methods and modify the implementation of --> to consider those as well, and for polymorphism, you'd also have to store the base class (or base classes, if multiple inheritance should be supported), and have --> look there if the ...



Only top voted, non community-wiki answers of a minimum length are eligible