I know this has been suggested before, but the only reason for rejection i found at the RCR archive was a dead end link...
Can someone explain to me why this shouldn't be implemented in Ruby:
   def foo(@a, @b = "foo", @@c = "bar")
     # do something
   end
   # should do the same as this
   def foo(a, b = "foo", c = "bar")
     @a  = a
     @b  = b
     @@c = c
     # do something
   end
I personally think it looks very interesting, especially since most initialize methods (at least most of those I write) just set instance and class variables.
Cheers,
Daniel
             
            
              
              
              
            
            
           
          
            
            
              Hrm, reminds me of an OptionParser trick that I like:
  options = Hash.new
  opts = OptionParser.new do |opts|
    opts.on('-r', '--reload', 'Reloads something') { |options[:reload]|
}
    opts.on('-q' ,'--quiet', 'Squelches messages') { |options[:quiet]|
}
  end
That said, I think with method definitions I'd still avoid putting
instance/class variables in the argument list.
             
            
              
              
              
            
            
           
          
            
            
              Selon Daniel Schierbeck <daniel.schierbeck@gmail.com>:
Can someone explain to me why this shouldn't be implemented in Ruby:
   def foo(@a, @b = "foo", @@c = "bar")
     # do something
   end
My eyes!!! >*_*<
   # should do the same as this
   def foo(a, b = "foo", c = "bar")
     @a  = a
     @b  = b
     @@c = c
     # do something
   end
I personally think it looks very interesting, especially since most
initialize methods (at least most of those I write) just set instance
and class variables.
I can see why you're interested (it shortens things quite a bit), but I think
it's a wrong idea. It's confusing to have method arguments that are not
method-local. Isn't that why the current behaviour of block arguments is going
to be changed? 
···
--
Christophe Grandsire.
http://rainbow.conlang.free.fr
It takes a straight mind to create a twisted conlang.
 
             
            
              
              
              
            
            
           
          
            
            
              
Selon Daniel Schierbeck <daniel.schierbeck@gmail.com>:
> Can someone explain to me why this shouldn't be implemented in Ruby:
>
>    def foo(@a, @b = "foo", @@c = "bar")
>      # do something
>    end
Yes. Matz doesn't like it.  (And I agree with Christophe -- my eyes!
 (And I agree with Christophe -- my eyes! 
-austin
···
--
Austin Ziegler * halostatue@gmail.com
               * Alternate: austin@halostatue.ca
 
             
            
              
              
              
            
            
           
          
            
            
              And what are the binding rules?
def foo(@a = 1, @@b = @a)
is equivalent to what? Common Lisp has two binding rules that generally used, e.g. let and let*. These would give you:
def foo(a, b)
   old_a = @a
   @a = a
   @@b = old_a
end
and
def foo(x, a, b)
   @a = a
   @@b = @a
end
You need both in CL.
Cheers,
Bob
···
On Oct 18, 2005, at 10:03 AM, Christophe Grandsire wrote:
Selon Daniel Schierbeck <daniel.schierbeck@gmail.com>:
Can someone explain to me why this shouldn't be implemented in Ruby:
   def foo(@a, @b = "foo", @@c = "bar")
     # do something
   end
My eyes!!! >*_*<
----
Bob Hutchison          -- blogs at <http://www.recursive.ca/hutch/>
Recursive Design Inc.  -- <http://www.recursive.ca/>
Raconteur              -- <http://www.raconteur.info/>
 
             
            
              
              
              
            
            
           
          
            
            
              It's a bit of an oversimplification to simply say that Matz doesn't
like, but I do understand why. It isn't exactly intuitive to set
instance variables in a method signature. (I'm not invoking POLS here,
I'm suggesting instead that it would be unnecessarily confusing.) That
said, it might be nice to have a language construct like C++'s
initialization list:
  class Person
  {
  Person() : name(""), age(-1)
  {
    // The rest of Person's default constructor here.
  }
  }
-austin
···
On 10/18/05, Daniel Schierbeck <daniel.schierbeck@gmail.com> wrote:
Austin Ziegler wrote:
Selon Daniel Schierbeck <daniel.schierbeck@gmail.com>:
Can someone explain to me why this shouldn't be implemented in Ruby:
  def foo(@a, @b = "foo", @@c = "bar")
    # do something
  end
Yes. Matz doesn't like it.  (And I agree with Christophe -- my
 (And I agree with Christophe -- my
eyes! 
Bollocks 
--
Austin Ziegler * halostatue@gmail.com
               * Alternate: austin@halostatue.ca