Hi Benjamin,

I've done this sort of thing with linked lists in Python... by putting all the nodes in a (Python) list, each with a unique ID, and using that ID to link the nodes to each other, etc. But the important thing for me to learn about here... "the goal"... is the self-instantiation aspect of the problem. The R/B tree is just an example I chose to show why you might want to so such a silly thing. ;)

Thanks for checking around, though...

On Jan 12, 2005, at 1:03 PM, Schollnick, Benjamin wrote:

Rayme,

        This sounds like a Linked List system...

        I was not able to find quickly a linked list module, but
        searching by "trees" at the Vaults produced a R/B tree...

        http://newcenturycomputers.net/projects/rbtree.html

        I've been out of touch, I have not heard about the Red/Black
        balanced tree algorithm...

        Hmm...  But take a look and see if it meets your
        requirements...

        But take a look at your implementation, if your just
        trying to make a linked list, you could just use a
        standard python list....

                        - Benjamin

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Rayme Jernigan
Sent: Wednesday, January 12, 2005 12:53 PM
To: pythonmac-sig@python.org
Subject: [Pythonmac-SIG] self-instantiating instances in pyhton


Hi,

I'm looking for a language to abuse for a project I'm working on. I
know a little Python, but I do not know if it can do this:
I'd like to
define some class "N" that instantiates objects that can instantiate
fresh new objects of that same class... without external controller
code.

You could use this capability, for example, to generate a red-black
tree-type data structure that implicitly instantiates a new node for
each new input d1, d2, d3... so on. The algorithm for each node could
be:

-- Toggle downstream L/R pointer
-- If no node there, instantiate one and link to it
-- if a node is there, pass the datum to it

The execution sequence as the tree builds itself out might look
something like this:

1. n0 = N(d0)   # new instance of N
                        # (downstream pointer default = "Left")
                        # (the first input data, d0, is
instantiated in node n0)
                        # nodes: n0

2. n0.send(d1)  # toggle n0's downstream pointer to "Right"
                        # on n0 there is no downstream node
right so instantiate a new
linked node right n1 with d1
                        # nodes: n0,n1

3. n0. send(d2) # toggle n0's downstream pointer "Left"
                        # in n0 there is no downstream node
left so instantiate n2 with d2
                        # nodes: n0,n1,n2

4. n0. send(d3) # toggle n0's downstream pointer "Right"
                        # there exists a downstream node right,
n1, so send d3 there
                        # toggle n1's downstream pointer "Right"
                        # in n1 there is no downstream node
right so instantiate n3 with d3
                        # nodes: n0,n1,n2,n3

5. n0. send(d4) # toggle n0's downstream pointer "Left"
                        # there exists a downstream node left,
n2, so send d4 there
                        # toggle n2's downstream pointer "Right"
                        # in n2 there is no downstream node
right so instantiate n4 with d4
                        # nodes: n0,n1,n2,n3,n4

6. n0.send(d5)  # toggle n0's downstream pointer "Right"
                        # there exists a downstream node right,
n1, so send d5 there
                        # toggle n1's downstream pointer "Left"
                        # in n1 there is no downstream node
left so instantiate n5 with d5
                        # nodes: n0,n1,n2,n3,n4,n5

7. n0.send(d6)  # So on...
                        # ...


Any thoughts about how to do this in Python appreciated. Possible at all? Thanks in advance,

-Rayme.

_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig



_______________________________________________ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig

Reply via email to