Thread: [Siop-development] Passing by value and by reference
Status: Pre-Alpha
Brought to you by:
slobberchops
From: Rapheal K. <ra...@ma...> - 2006-06-29 07:43:36
|
I've added a "ref" and "val"... err... modifier? Not sure what to call them. They are intended to be simple markers that a host language can use as a hint to the bridge so that the bridge knows to over-ride the default parameter behavior for an object being passed to a peer either via parameters or return value. Remember, scalar values are passed by value by default while collections are passed by reference by default. These little keyword thingies can over-ride this default behavior. So, let's say you were calling a method that uses a list. It might be the case that the programmer can figure out that it would be an optimization to send the list to the other side, especially if the code over there does a lot of random access: remote_object.helpful_method( val( [ "a", "b", "c", "d" ] ) ) The example above would send a reference to the list if it were not for the modifier wrapper object. This is very useful in the example wxWidgets code where we needed to construct native Python tuples and dictionaries in order to be able to create new classes: # Helper method to define Python types # Class creation requires actual Python tuples, not pretenders # TODO: This can be disposed of when it is possible to pass # tuples by-value def tuple( *stuff ) list = $types.ListType.call for thing in stuff list.append( thing ) end $types.TupleType( list ) end # Helper method to define Python class # In the future, may provide helper library to do this def pyclass( name, *parents, &definition ) klass = $types.ClassType( name.to_s, tuple( *parents ), $types.DictType.call ) klass.instance_eval &definition unless definition.nil? klass end Now it's a little easier: # Helper method to define Python class # In the future, may provide helper library to do this def pyclass( name, *parents, &definition ) klass = $types.ClassType( name.to_s, Siop::val( Siop::Tuple( *parents ) ), Siop::val( {} ) ) klass.instance_eval &definition unless definition.nil? klass end Anyone who thinks they follow this and cares to voice their opinion as to wether this seems ok or is cumbersome, or thinks there might be a more preferable way, please tell me. - Rafe |
From: Kevin S. <wx...@qu...> - 2006-07-03 14:31:11
|
On Thu, 2006-06-29 at 00:43 -0700, Rapheal Kaplan wrote: > I've added a "ref" and "val"... err... modifier? Not sure what to call > them. Seems ok. > Remember, scalar values are passed by value by default while collections are > passed by reference by default. Still sounds irritating to me, as one who is constantly fuming about the scalar/object distinction in Java. Maybe this wouldn't be so bad, since as I mentioned Ruby passes ints by reference but they appear to be passed by value since they are immutable. > Now it's a little easier: > > > # Helper method to define Python class > # In the future, may provide helper library to do this > def pyclass( name, *parents, &definition ) > klass = $types.ClassType( name.to_s, > Siop::val( Siop::Tuple( *parents ) ), > Siop::val( {} ) > ) > klass.instance_eval &definition unless definition.nil? > klass > end I would hope that code like this would be part of the siop framework, at least at some point. You're not going to expect a siop user like me to write or maintain code like that, are you? I had a similar reaction to the wxRython snippets...they seemed to be a mix of generic and specific code. I don't want to see the sausage-making generic code. It's all about encapsulating the icky parts into the framework so clients like us can just use remote classes and objects as if they were local. Something like this would be cool: class MyApp < siop.remote_class(:wx, :App) def on_init # blah blah blah end end Kevin |
From: Rapheal K. <ra...@ma...> - 2006-07-03 17:31:10
|
>> Now it's a little easier: >> >> >> # Helper method to define Python class >> # In the future, may provide helper library to do this >> def pyclass( name, *parents, &definition ) >> klass = $types.ClassType( name.to_s, >> Siop::val( Siop::Tuple( *parents ) ), >> Siop::val( {} ) >> ) >> klass.instance_eval &definition unless definition.nil? >> klass >> end >> > > I would hope that code like this would be part of the siop framework, at > least at some point. You're not going to expect a siop user like me to > write or maintain code like that, are you? > > Meaning, siop will include code for creating classes? I think that class creation should be one of the levels. Then it would be a lot simpler to code the above thingy. There would, for one, be no need to do the val thing nor the tuple thing, because the bridge on the receiving side could take care of all of that for you. > I had a similar reaction to the wxRython snippets...they seemed to be a > mix of generic and specific code. I don't want to see the sausage-making > generic code. It's all about encapsulating the icky parts into the > framework so clients like us can just use remote classes and objects as > if they were local. > > Something like this would be cool: > > class MyApp < siop.remote_class(:wx, :App) > def on_init > # blah blah blah > end > end > Right, that's what I am thinking. |