From: Paul Prescod Date: 2001-06-22T06:39:25+09:00 Subject: [ruby-talk:16727] Re: Simulating call-by-reference in Ruby Tobin Baker wrote: > >... > > Python doesn't have anything like Perl's reference operator, so the > mapping spec recommends passing inout parameters like in parameters, > and returning them in a tuple together with the return value (if any) > and all out parameters. To me this is somewhat inelegant and does a > rather poor job of emulating inout semantics, but there may be no > alternative in Python. In Ruby, however, we *can* simulate reference > parameters by having the caller pass a symbol instead of the variable > itself, getting the value of the variable for that symbol from the > caller's context (using eval), and then using eval again to write > another value into that variable. I think that your proposed solution is actually possible in Python but I question your basic premise. Doing things in a way that closely emulates "inout semantics" is less important than doing things in a way that is idiomatic in the actual language. If languages like Python and Ruby don't have call-by-reference, I think it is more confusing than helpful to add it to the language through tricks. Python functions that want to return multiple arguments return tuples. Java uses holder classes[1]. Ruby has tuples also, what's wrong with using them? http://industry.ebi.ac.uk/~senger/ws-corba/home/talks/corba_java_mapping/tsld006.htm -- Take a recipe. Leave a recipe. Python Cookbook! http://www.ActiveState.com/pythoncookbook