From: Mathieu Bouchard Date: 2005-03-22T18:20:21+09:00 Subject: Re: RCR 296: Destructive methods return self On Tue, 22 Mar 2005, Glenn Parker wrote: > > (3) introduce "real" multiple return values ala common lisp, and let > > the first returned value as the receiver and the second return > > value is boolean value to denote success/failure. > Ick. Ever wonder why other languages don't do this? Perl shows some cases of LISP-style multiple return values. Especially, functions can detect whether they're in scalar-context or list-context, and some of them may return ($a,$b,$c) in list-context while returning just $a in scalar-context. The biggest problem with LISP must be that the form is called (GET-HIDDEN-RETURNED-MULTIPLE-VALUE-DATA-STUFF-USING-LENGTHY-MACRO-NAME) The most similar thing in Ruby may be that you can do: a, = foo() a,b,c = foo() But there are so many things wrong with it that its usefulness is very limited. It's too far from being the thing. > Oooo, pretty! Seems like it might defeat the goal of optimizing > things, unless the reference counting could reduce the overall impact > of garbage collection. There's a reference-counting system that only uses two bits (and so could fit in the flags section of a Ruby boxed-object) and has four different values: 1, 2, 3, and "more". This is based on the fact that most objects have very few references to them. Then, for the "more" case, a Mark-and-sweep can do the job, and you don't have to run it nearly as often as if the Mark-and-sweep had to do all the job. However, I'm not sure it's *that* good. Plus, I don't know what it would do to the Ruby-FFI. I've seen Python-FFI C code, and INCREF DECREF INCREF DECREF is about as annoying as Python's tab tab tab self self self () () () or Ruby's end end end end end. I'd rather just define mark() and free(). > When I'm playing with simple algorithms, disabling garbage collection > seems to yield a guaranteed 20% speedup, even for relatively short tasks > (< 30 sec.). At some point there was a big problem in Ruby dealing with large numbers of objects. I don't recall which version got it fixed but I'm pretty sure it wasn't there before 1.8.0. If you happen to still run Ruby 1.6.8 for example, then I think you don't have it. If the total number of objects got very large, this meant a *tremendous* speedup. > (5) add alternative destructive methods with different names that > always return self. > This is the change with the least impact, but I realize it is ugly. I know how to solve the problem!!!!!!!! add support for multiple bangs signs at the end of methods!!!!!!! like, foo.gsub!!!!!!!!!!!!!!!!!!! this is so ELiTE!!!!!!!!!!!!!!111 W00t!!!!!!!!!!!!!1 ok, sorry for this one. _____________________________________________________________________ Mathieu Bouchard -=- Montr�al QC Canada -=- http://artengine.ca/matju