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

Stef Mientki stef.mientki at gmail.com
Tue Feb 17 15:49:00 CET 2009


thanks Diez,

Diez B. Roggisch wrote:
> Stef Mientki schrieb:
>> 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.
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
> So knowing if that object is mutable is irrelevant I'd say.
>
> Diez
> -- 
> http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list