MathGroup Archive 2010

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

Search the Archive

Re: MathOO: Adding Object Orientation to Mathematica

  • To: mathgroup at
  • Subject: [mg113681] Re: MathOO: Adding Object Orientation to Mathematica
  • From: "ph.tchaa at" <ph.tchaa at>
  • Date: Sun, 7 Nov 2010 05:12:43 -0500 (EST)
  • References: <ib38rs$f0j$>

On 11=E6=9C=886=E6=97=A5, =E4=B8=8B=E5=8D=885=E6=99=8258=E5=88=86, "
. at" < at> wrote:
> I have written a Mathematica package: MathOO, which adds object
> orientation capability to Mathematica. It is currently in beta
> version, 1.0b. It allows you to use syntax very similar to Python,
> which is very easy to use.
> Please read the above link for more information.
> You may discuss about it using
> in Voofie as well. Thank you.

In developing the MathOO package:,
I encountered a problem with Mathematica.

The problem is, I would like to have garbage collector, so that user
don't have to explicitly deleting the object after using it. For

Object1.$init$[self_]:= Return[];

In the above two lines, I just defined Object1 to be a new class, and
the constructor to be an empty function. If you are familiar with
Python, you should see the similarity with __init__().

To instantiate an Object1, I do:

object1 = new[Object1][]

The output is:

Out: object$13

Here, object$13 is an temporary variable. What I want is, when there
are no references to this temporary variable, it should be deleted
automatically. But it doesn't work as expected. I have identified the
problem to be the following:

In:    y = Module[{x}, x[1] = 2; x]
Out: x$117

In:    FullDefinition[y]
Out: y = x$117
       Attributes[x$117] = {Temporary}
       x$117[1] = 2

Since y holds a reference of x$117, so x$117 is not removed yet. Now
let's delete the reference by setting the value of y to 1:

In:  y = 1;

However, x$117 is still here:

In:     Definition[x$117]
Out: Attributes[x$117] = {Temporary}
         x$117[1] = 2

But I expected the variable to be removed since it is no longer
referenced. From the manual of Mathematica, it said:

    Temporary symbols are removed if they are no longer referenced:

So, is it a bug of Mathematica? Or is there any workaround methods? I
am using Mathematica 7.0. Thank you very much.

  • Prev by Date: Re: Re: MathLink and c++ compiler
  • Next by Date: Re: Programmatically creating functions of many variables
  • Previous by thread: MathOO: Adding Object Orientation to Mathematica
  • Next by thread: Re: MathOO: Adding Object Orientation to Mathematica