From: Eric Mahurin Date: 2005-05-10T03:09:13+09:00 Subject: Re: RCR 304: reference/pointer concept Here are a couple of things this might be useful for (I just put these in the RCR). I'm sorry I didn't provide something more concrete sooner. Regarding #2, I've used references to hash values many times to get better efficiency (in perl). i.e. $a = \$hash{$key} # read and modify $$a Doing this, only one lookup is needed (for making the ref) as opposed to 2 (for the get and set). As far as I know, we can't get this extra efficiency for hash values in Ruby. You can create references to hash values in my Ruby implementation, but it doesn't give you any additional efficiency. That would need to be done at the C level. And that would be useful - especially for large hashes. 1. pass-by-reference or pass an lvalue. From what I understand, the way you would write/use a Ruby method that modified lvalues right now, would be like this: def byvalue(*args) # read and modify args args end a,b,c = *byvalue(a,b,c) With references, you could do this: def byref(*args) # read and modify args[i][] end byref(ref{:a},ref{:b},ref{:c}) With this simple variable case, there isn't much advantage, but when you are dealing with something deep within an object, it can offer an advantage: a["hi"][3],io.pos = *byvalue(a["hi"][3],io.pos) vs. byref(a["hi"].ref[3],io.ref.pos) Also, with the byvalue case, you are forced into the assign, whereas byref may choose not to do this assign. Depending on the object, this could even prevent an exception (i.e. IO#pos=). 2. Although not addressed in this implementation, a reference could provide some efficiency when ther is some work that could be saved when you get or set the same thing 2 or more times. A primary example of this would be a reference to a hash value. With a good implementation of a reference to a hash value, you would only need to do the hash lookup once (while making the reference). Compare this to what you have now - you do a hash lookup every time you get/set a given hash value. --- Bill Atkins wrote: > What would this accomplish? > > On 5/9/05, Eric Mahurin wrote: > > I just submitted RCR 304 with the rubyforge 'reference' > > project/gem implementation: > > > > http://www.rcrchive.net/rcr/show/304 > > > > Go vote and make comments on it! > > > > Discover Yahoo! > > Use Yahoo! to plan a weekend, have fun online and more. > Check it out! > > http://discover.yahoo.com/ > > > > > > > -- > Bill Atkins > > __________________________________ Yahoo! Mail Mobile Take Yahoo! Mail with you! Check email on your mobile phone. http://mobile.yahoo.com/learn/mail