how to detect if an object is "simple" (not a pointer, unmutable ) ?

S

Stef Mientki

hello,

I'm making a virtual machine,
in which (small) pieces of software (called bricks) are connected,
by connecting an output of a brick to the input of another brick.

A connection between 2 bricks may be of any type,
so it might be simple integer,
or a multi-nested dictionary / list or whatsoever .

Connections are made with the following statement (in simplified form)

Brick2.In = Brick2.Out

Now if the connection is a complex object, e.g. a list,
Brick2.In and Brick2.Out points to the same object,
and can automatically exchange information.

Now if the connection consists of a simple integer,
the statement Brick2.In = Brick2.Out
just assigns once a value to Brick2,
so there's no real communication anymore.
I solved that by adding modify-flags and receiver lists.

The problem is how can I determine
if a connection is a pointer or not ?
Which I'm not sure might be the same as mutable ?
( The type of connection need not be a standard Python type,
but might be any type created by the user. )

thanks,
Stef Mientki
 
D

Diez B. Roggisch

Stef said:
hello,

I'm making a virtual machine,
in which (small) pieces of software (called bricks) are connected,
by connecting an output of a brick to the input of another brick.

A connection between 2 bricks may be of any type,
so it might be simple integer,
or a multi-nested dictionary / list or whatsoever .

Connections are made with the following statement (in simplified form)

Brick2.In = Brick2.Out

Now if the connection is a complex object, e.g. a list,
Brick2.In and Brick2.Out points to the same object,
and can automatically exchange information.

Now if the connection consists of a simple integer,
the statement Brick2.In = Brick2.Out
just assigns once a value to Brick2,
so there's no real communication anymore.
I solved that by adding modify-flags and receiver lists.

The problem is how can I determine
if a connection is a pointer or not ?
Which I'm not sure might be the same as mutable ?
( The type of connection need not be a standard Python type,
but might be any type created by the user. )

AFAIK there is no distinction possible by some attribute or function. I
guess your safest bet is to provide a discreet list of immutables, and
check objects for them being subclass of these. If yes, create the
needed communication channels.

OTOH, the better option might even be to intercept the setting of
objects on your bricks. If somebody sets a value on some brick's "slot",
this is *always* something that needs to be communicated - it could be a
new list, couldn't it? So knowing if that object is mutable is
irrelevant I'd say.

Diez
 
S

Stef Mientki

thanks Diez,
AFAIK there is no distinction possible by some attribute or function.
I guess your safest bet is to provide a discreet list of immutables,
and check objects for them being subclass of these.
Yes that's a reasonable approach.
Still I find it strange that you can't detect if an object is immutable.
If yes, create the needed communication channels.

OTOH, the better option might even be to intercept the setting of
objects on your bricks. If somebody sets a value on some brick's
"slot", this is *always* something that needs to be communicated
if there are receivers / listeners, Yes
- it could be a new list, couldn't it?
I've thought about that, but it makes the creation of the Bricks (which
should be possible by novices) more complex.
By not making it a list on default, the execution of a brick might be as
simple as:
Out = 3 * In
But of course I could wrap that up, so it'll become a list,
I'll think about that.

thanks,
Stef
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top