Yukihiro Matsumoto <matz@ruby-lang.org> writes:
Hi,
>
>I'm trying to understand how to call methods in Ruby. Is it possible to
>call parameters in different order? E.g. in Python it is very clear and
>simple to use.
>
>def fun(a=1,b=2):
> return 'a:%s, b:%s' % (a,b)
>
>print fun(b=10, a=20) # a:20, b:10
>print fun(b=111) # a:1, b:111
>Is it possible that such basic and usefull feature is not implemented in
>Ruby??
No. Keyword arguments like
fun(b:20, a:10)
is planned, but named keyword arguments will be separated from
positional arguments still.
To what extend will these be checked?
I.e., if I have a method
def foo(argone: 3, argtwo: 42); end
What will happen when I call
foo(bleh: nil) ?
(and btw, can one write foo bleh: nil?)
···
In message "Re: different order of parameters..." > on Tue, 2 Aug 2005 18:11:05 +0900, JZ <usenet@zabiello.com> writes:
matz.
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org
Hi,
No. Keyword arguments like
fun(b:20, a:10)
is planned, but named keyword arguments will be separated from
positional arguments still.
To what extend will these be checked?
I.e., if I have a method
def foo(argone: 3, argtwo: 42); end
What will happen when I call
foo(bleh: nil) ?
It's not settled but I guess nothing will happen, just like we had
&allow-other-keys a la CommonLisp, just because "super" may accept
more keywords. I would like to provide some scheme to check invalid
keywords like you mentioned, but not yet have had a good idea.
(and btw, can one write foo bleh: nil?)
I'm not suer how "foo bleh: nil?" means. If it means to check whether
a keyword is given by the caller, you can accept a keyword hash by
foo(**keys)
then check if there's "bleh" in it.
matz.
···
In message "Re: different order of parameters..." on Tue, 2 Aug 2005 22:22:23 +0900, Christian Neukirchen <chneukirchen@gmail.com> writes:
Yukihiro Matsumoto <matz@ruby-lang.org> writes:
>> No. Keyword arguments like
>>
>> fun(b:20, a:10)
>>
>> is planned, but named keyword arguments will be separated from
>> positional arguments still.
>
>To what extend will these be checked?
>
>I.e., if I have a method
>
> def foo(argone: 3, argtwo: 42); end
>
>What will happen when I call
>
> foo(bleh: nil) ?
It's not settled but I guess nothing will happen, just like we had
&allow-other-keys a la CommonLisp, just because "super" may accept
more keywords. I would like to provide some scheme to check invalid
keywords like you mentioned, but not yet have had a good idea.
Good checking is IMO very important... too many dumb errors can happen
because of wrong speling. I'm not sure if undefined keywords should
go unpassed to super...
>(and btw, can one write foo bleh: nil?)
I'm not suer how "foo bleh: nil?" means. If it means to check whether
a keyword is given by the caller, you can accept a keyword hash by
foo(**keys)
then check if there's "bleh" in it.
I rather meant if you can drop the parentheses... Smalltalk ahead 
···
matz.
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org
Citát Yukihiro Matsumoto <matz@ruby-lang.org>:
>I rather meant if you can drop the parentheses... Smalltalk ahead 
I guess you would be able to.
matz.
One of the cooler of syntax features making a comeback? Rawr.
Will the core API tend towards using keyword arguments, or rather providing
alternatives using them to methods with positional arguments? Or will it be
possible to provide a way to call a method using both ways? Possibly with some
extra syntax (*ducks in a corner and hides*), or possibly doing that using
alias some way - SmallScript/S# comes to mind.
Or is it too early to ask anyway?
David
Yukihiro Matsumoto <matz@ruby-lang.org> writes:
Hi,
>Will the core API tend towards using keyword arguments, or rather providing
>alternatives using them to methods with positional arguments?
It would, but it takes years for libraries to adopt keyword arguments.
matz.
Just imagine:
mystring.gsub(/bar/, with: "foo").tr "abc", to: "xyz"
[1, 2, 3].inject 0, into: { |a,e| a + e }
(Actually, the comma is disturbing.
And no, I don't want to tweak
Ruby into the next Self.)
···
In message "Re: different order of parameters..." > on Wed, 3 Aug 2005 21:58:17 +0900, david@vallner.net writes:
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org
Yukihiro Matsumoto <matz@ruby-lang.org> writes:
> Hi,
>
>
> >Will the core API tend towards using keyword arguments, or rather providing
> >alternatives using them to methods with positional arguments?
>
> It would, but it takes years for libraries to adopt keyword arguments.
>
> matz.
Just imagine:
mystring.gsub(/bar/, with: "foo").tr "abc", to: "xyz"
[1, 2, 3].inject 0, into: { |a,e| a + e }
wouldn't
[1,2,3].inject 0, :with { |a,e| a+e }
make more sense. (Or even "using:"). I always thought of inject as
injecting a seed and a function into the enumerable.
(Ohh, I know it just a sidenote and may not add anything valuable to
the discussion 
regards,
Brian
···
On 03/08/05, Christian Neukirchen <chneukirchen@gmail.com> wrote:
> In message "Re: different order of parameters..." > > on Wed, 3 Aug 2005 21:58:17 +0900, david@vallner.net writes:
(Actually, the comma is disturbing.
And no, I don't want to tweak
Ruby into the next Self.)
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org
--
http://ruby.brian-schroeder.de/
Stringed instrument chords: http://chordlist.brian-schroeder.de/
Brian Schröder <ruby.brian@gmail.com> writes:
Just imagine:
mystring.gsub(/bar/, with: "foo").tr "abc", to: "xyz"
[1, 2, 3].inject 0, into: { |a,e| a + e }
wouldn't
[1,2,3].inject 0, :with { |a,e| a+e }
make more sense. (Or even "using:"). I always thought of inject as
injecting a seed and a function into the enumerable.
Except it's called inject:into: in Smalltalk.
···
On 03/08/05, Christian Neukirchen <chneukirchen@gmail.com> wrote:
Brian
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org