MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: fyi, small note on using Mathematica for object based programming

On Thursday, April 5, 2012 5:54:06 AM UTC-4, Nasser M. Abbasi wrote:
> Just FYI,
> I wrote this small note on using Mathematica for object-based
> programming. I found that it works really well for me.
> Nothing too advanced, just a simple way of using Module[] but
> in a way to emulate object based programming that I did not know
> about before.
> --Nasser

I like it, and it resembles a technique that I've been using for several years.

I called my version "Loom" (Lightweight Objects and Options in Mathematica). In addition to encapsulating state through convenient closures, and providing simpler syntax for option handling, it enables another level of granularity in package files. So packages can grow quite large this way (I like single-file deployments). Large packages remain easy to read with the lexical "locality" provided by Loom without burdening symbol syntax. There are no special operators---just a few infrequent keywords: 'static', 'class', and 'type'. There is provision for inheritance and upcalls which I rarely use (keyword 'super', largely untested).

Loom grew out of need in my application development; it was not forced from a desire to imitate a particular paradigm. It has proven itself over time in a variety of modeling, simulation, and analysis tasks.

But! I do not see an easy way to implement /automatic/ serialization of objects with this approach. The reliance on $ModuleNumber for pseudo-pointers 
throws a wrench in it, I think.

I'm glad Nasser documented his version. Someday I might document mine.

Vince Virgilio

  • Prev by Date: Re: Deleting expressions containing a certain head
  • Next by Date: Re: Replace each f in f^n to different variables
  • Previous by thread: Re: fyi, small note on using Mathematica for object based programming
  • Next by thread: Bug in pattern test, or I did something wrong?