[#393012] Basic Ruby performance — Dmitry Nikiforov <dniq@...>

Hello all!

43 messages 2012/02/02
[#393013] Re: Basic Ruby performance — Dmitry Nikiforov <dniq@...> 2012/02/02

Here's another example with significantly bigger performance difference:

[#393015] Re: Basic Ruby performance — Ryan Davis <ryand-ruby@...> 2012/02/02

[#393016] Re: Basic Ruby performance — Peter Vandenabeele <peter@...> 2012/02/02

On Fri, Feb 3, 2012 at 12:20 AM, Ryan Davis <ryand-ruby@zenspider.com>wrote:

[#393020] Re: Basic Ruby performance — Ryan Davis <ryand-ruby@...> 2012/02/03

[#393076] Problem migrating to Ruby 1.9.2 — Patrick Bayford <pbayford@...>

Some assistance please - I have a Ruby project, which I started in Ruby

10 messages 2012/02/03

[#393164] Using _ like in Scala? — Marc Heiler <shevegen@...>

fruits = %w( apple banana orange )

27 messages 2012/02/06
[#393201] Re: Using _ like in Scala? — Tony Arcieri <tony.arcieri@...> 2012/02/07

On Mon, Feb 6, 2012 at 10:54 AM, Marc Heiler <shevegen@linuxmail.org> wrote:

[#393204] Re: Using _ like in Scala? — Eric Christopherson <echristopherson@...> 2012/02/07

On Mon, Feb 6, 2012 at 7:21 PM, Tony Arcieri <tony.arcieri@gmail.com> wrote:

[#393206] Re: Using _ like in Scala? — Tony Arcieri <tony.arcieri@...> 2012/02/07

On Mon, Feb 6, 2012 at 5:56 PM, Eric Christopherson <

[#393208] Re: Using _ like in Scala? — Kevin <darkintent@...> 2012/02/07

On Mon, Feb 6, 2012 at 9:07 PM, Tony Arcieri <tony.arcieri@gmail.com> wrote:

[#393216] Re: Using _ like in Scala? — Robert Klemme <shortcutter@...> 2012/02/07

On Tue, Feb 7, 2012 at 6:56 AM, Kevin <darkintent@gmail.com> wrote:

[#393219] Re: Using _ like in Scala? — Josh Cheek <josh.cheek@...> 2012/02/07

On Tue, Feb 7, 2012 at 4:47 AM, Robert Klemme <shortcutter@googlemail.com>wrote:

[#393220] Re: Using _ like in Scala? — Robert Klemme <shortcutter@...> 2012/02/07

On Tue, Feb 7, 2012 at 1:00 PM, Josh Cheek <josh.cheek@gmail.com> wrote:

[#393240] Re: Using _ like in Scala? — Josh Cheek <josh.cheek@...> 2012/02/08

On Tue, Feb 7, 2012 at 9:15 AM, Robert Klemme <shortcutter@googlemail.com>wrote:

[#393254] Re: Using _ like in Scala? — Robert Klemme <shortcutter@...> 2012/02/08

On Wed, Feb 8, 2012 at 3:43 AM, Josh Cheek <josh.cheek@gmail.com> wrote:

[#393259] Re: Using _ like in Scala? — Josh Cheek <josh.cheek@...> 2012/02/08

On Wed, Feb 8, 2012 at 5:58 AM, Robert Klemme <shortcutter@googlemail.com>wrote:

[#393181] Tork 18.0.0 — "Suraj N. Kurapati" <sunaku@...>

Tork - Test with fork - https://github.com/sunaku/tork#readme

16 messages 2012/02/06
[#393183] Re: [ANN] Tork 18.0.0 — Bartosz Dziewoński <matma.rex@...> 2012/02/06

You have faster major version release cycle than Chrome...

[#393189] Re: [ANN] Tork 18.0.0 — Quintus <sutniuq@...> 2012/02/06

Am 06.02.2012 22:07, schrieb Bartosz Dziewoナгki:

[#393203] Re: Tork 18.0.0 — Suraj Kurapati <sunaku@...> 2012/02/07

Marvin G=C3=BClker wrote in post #1044440:

[#393347] Symbol garbage collection — Dido Sevilla <dido.sevilla@...>

I've always wondered why Ruby didn't do garbage collection of symbols,

13 messages 2012/02/10

[#393402] Who Administrates this list and how can the community help save this list from the noise. — andrew mcelroy <sophrinix@...>

It is very clear that this list has been under a incredibly heavy

21 messages 2012/02/11
[#393403] Re: Who Administrates this list and how can the community help save this list from the noise. — serialhex <serialhex@...> 2012/02/11

+1

[#393407] Re: Who Administrates this list and how can the community help save this list from the noise. — Cathy Alomari <cathy1428@...> 2012/02/11

Good luck, I doubt anyone is paying attention. I have seen numerous

[#393410] Re: Who Administrates this list and how can the community help save this list from the noise. — "Darryl L. Pierce" <mcpierce@...> 2012/02/11

On Sat, Feb 11, 2012 at 1:12 PM, Cathy Alomari <cathy1428@gmail.com> wrote:

[#393430] Re: Who Administrates this list and how can the community help save this list from the noise. — Cathy Alomari <cathy1428@...> 2012/02/13

On Sat, Feb 11, 2012 at 10:48 AM, Darryl L. Pierce <mcpierce@gmail.com>wrote:

[#393432] Re: Who Administrates this list and how can the community help save this list from the noise. — Bartosz Dziewoński <matma.rex@...> 2012/02/13

2012/2/13 Cathy Alomari <cathy1428@gmail.com>:

[#393434] Re: Who Administrates this list and how can the community help save this list from the noise. — Rimantas Liubertas <rimantas@...> 2012/02/13

> Have you tried mailing ruby-talk-ctl@ruby-lang.org (mailto:ruby-talk-ctl@ruby-lang.org) with "unsubscribe"

[#393412] the ruby syntax — maven apache <apachemaven0@...>

Hi:

19 messages 2012/02/12
[#393413] Re: the ruby syntax — Bartosz Dziewoński <matma.rex@...> 2012/02/12

When a hash is the last argument to a method, you can skip its open-

[#393416] Re: the ruby syntax — maven apache <apachemaven0@...> 2012/02/12

2012/2/12 Bartosz Dziewo=C5=84ski <matma.rex@gmail.com>

[#393435] Re: the ruby syntax — Saji Hameed <saji@...> 2012/02/13

On Sun, Feb 12, 2012 at 10:49 PM, maven apache <apachemaven0@gmail.com> wro=

[#393546] Difference between 1.9.2 and 1.9.3 — James French <James.French@...>

module A <- line 1

12 messages 2012/02/20
[#393558] Re: Difference between 1.9.2 and 1.9.3 — Dave Aronson <rubytalk2dave@...> 2012/02/21

On Mon, Feb 20, 2012 at 12:25, James French

[#393548] Accessing a local variable through a symbol — Ralph Shnelvar <ralphs@...32.com>

Let's say I have

11 messages 2012/02/20

[#393671] Rubymoticons — Dave Aronson <rubytalk2dave@...>

I was demonstrating injection of a symbol, and noticed a familiar

12 messages 2012/02/28

Re: Error with splat params in method definition

From: Robert Klemme <shortcutter@...>
Date: 2012-02-06 10:01:46 UTC
List: ruby-talk #393147
On Mon, Feb 6, 2012 at 5:20 AM, Jeremy Bopp <jeremy@bopp.net> wrote:
> On 02/05/2012 07:19 PM, Jones Lee wrote:
>> I'd like to ask why having:
>>
>> ```
>> def my_method(*param1, param2 =3D "default"); end
>> ```
>>
>> returns
>>
>> ```
>> SyntaxError: (irb):15: syntax error, unexpected '=3D', expecting ')'
>> ```

This cannot reliably be evaluated because there is an ambiguity.  Will
my_method(1) invoke with param1 =3D [] and param2 =3D 1 or with param1 =3D
[1] and param2 =3D "default"?  No machine can decide this.

>> My workaround is explicitly wrap param in brackets like this:
>>
>> ```
>> def my_method((*param1), param2 =3D "default"); end
>> ```
>
> Have you tried calling your method with the workaround with exactly 0 or
> more than 2 arguments? =A0I think you'll find that your workaround doesn'=
t
> really work around anything aside from the syntax error.
>
> Now, I could be wrong about the details, and I believe there are some
> subtle changes coming soon with respect to parameter handling for
> methods, but I'll see if I can clarify what is going on. =A0Ruby attempts
> to associate method parameters as follows:
>
> 1) Assign the first parameters given in the method call to all the
> positional parameters that do not have defaults defined and report an
> error if there are not enough given parameters to do this.
> 2) If there are still more given parameters, assign those to the
> positional parameters that would otherwise have defaults set.
> 3) Assign any remaining parameters that are NOT key-value definitions
> for a hash to the splat parameter.
> 4) Assign the key-value hash definitions to the final parameter as a
> single hash.

Not sure whether the order between 3 and 4 is correct or even matters.
 But that looks like a pretty good description of what's going on -
apart from the fact that splash can occur anywhere and hence step one
does not only eat leading parameters.

> These rules require that method definitions first specify positional
> parameters without defaults, followed by positional parameters with
> defaults, followed by the splat parameter, followed by a single
> parameter that will receive the hash parameters.

It's not exactly correct any more with 1.9.*: you can have the splat
in other places than the last position:

irb(main):007:0> def f(a,*b,c) p a,b,c end
=3D> nil
irb(main):008:0> f 1
ArgumentError: wrong number of arguments (1 for 2)
        from (irb):7:in `f'
        from (irb):8
        from /opt/bin/irb19:12:in `<main>'
irb(main):009:0> f 1, 2
1
[]
2
=3D> [1, [], 2]
irb(main):010:0> f 1, 2, 3
1
[2]
3
=3D> [1, [2], 3]
irb(main):011:0> f 1, 2, 3, 4
1
[2, 3]
4
=3D> [1, [2, 3], 4]

> I'm sure that I'm going to get all sorts of corrections about the above,
> but that's the gist as I understand things at least.

You are correct in that there _are_ limitations.

> It appears that you would like to instead specify your positional
> parameters (param2) after your splat parameter (param1). =A0I don't
> believe Ruby yet has any facility to handle that in the language,

It can do it but not with defaults:

irb(main):012:0> def f(*a, b, c) p a, b, c end
=3D> nil
irb(main):013:0> f 1
ArgumentError: wrong number of arguments (1 for 2)
        from (irb):12:in `f'
        from (irb):13
        from /opt/bin/irb19:12:in `<main>'
irb(main):014:0> f 1,2
[]
1
2
=3D> [[], 1, 2]
irb(main):015:0> f 1,2,3
[1]
2
3
=3D> [[1], 2, 3]
irb(main):016:0> f 1,2,3,4
[1, 2]
3
4
=3D> [[1, 2], 3, 4]

> but you can emulate it:
>
> def my_method(*params)
> =A0param1 =3D params
> =A0param2 =3D params.size > 1 ? params.pop : "default"
> =A0...
> end

Yeah, but who wants to read such code?  That will be a heck of a
difficult thing to debug.  I'd rather stick with standard features
because they also allow for automated error checking and reporting.

Kind regards

robert


--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

In This Thread

Prev Next