Splat operator gives an SystemStackError

Discussion in 'Ruby' started by Gunther Diemant, Mar 4, 2011.

  1. Hello,
    when I'm running this programm

    a1 = (1..150000).to_a

    def splat_test(*args)
    puts args.size
    end

    splat_test(*a1)

    I get a SystemStackError exception.

    My setup:
    Arch Linux
    rvm ruby 1.9.2-p0 (also tried with 1.9.2-p180)

    Can anyone reproduce this behavior or is this a problem with my ruby
    install?

    PS: I hope this is the right place to ask this question, if not I'm sorry.

    Greetings
    Gunther
    Gunther Diemant, Mar 4, 2011
    #1
    1. Advertising

  2. On 03/04/2011 03:40 AM, Gunther Diemant wrote:
    > Hello,
    > when I'm running this programm
    >
    > a1 = (1..150000).to_a
    >
    > def splat_test(*args)
    > puts args.size
    > end
    >
    > splat_test(*a1)
    >
    > I get a SystemStackError exception.
    >
    > My setup:
    > Arch Linux
    > rvm ruby 1.9.2-p0 (also tried with 1.9.2-p180)
    >
    > Can anyone reproduce this behavior or is this a problem with my ruby
    > install?
    >
    > PS: I hope this is the right place to ask this question, if not I'm
    > sorry.
    >
    > Greetings
    > Gunther
    >


    You are trying to pass in 150,000 arguments to a method. Surprisingly,
    this did work for me on 1.8.7-p302. However, 1.9 has very different
    internals. This is a complete guess, but it may be trying to push all of
    those arguments onto the stack, giving the resulting error.

    -Justin
    Justin Collins, Mar 4, 2011
    #2
    1. Advertising

  3. Am 04.03.2011 12:48, schrieb Justin Collins:
    > You are trying to pass in 150,000 arguments to a method. Surprisingly,
    > this did work for me on 1.8.7-p302. However, 1.9 has very different
    > internals. This is a complete guess, but it may be trying to push all
    > of those arguments onto the stack, giving the resulting error.
    >
    > -Justin
    >

    So, you think there is a limit to the number of method arguments (at
    least in 1.9)?
    I came across this problem, when I tried some different approaches to
    convert an array to a hash (inspired by
    http://exposinggotchas.blogspot.com/2011/03/fun-with-ruby-arrays-hashes-and.html).
    At least, the splat isn't necessary in this case.

    -Gunther
    Gunther Diemant, Mar 4, 2011
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joel VanderWerf
    Replies:
    2
    Views:
    85
  2. Jesper Olsen
    Replies:
    7
    Views:
    553
    Van Jacques
    Jan 16, 2004
  3. Pedro Del Gallego

    splat operator Question.

    Pedro Del Gallego, May 20, 2007, in forum: Ruby
    Replies:
    1
    Views:
    100
    Pedro Del Gallego
    May 20, 2007
  4. Thufir
    Replies:
    6
    Views:
    111
    Thufir
    Mar 19, 2008
  5. RichardOnRails

    What am I missing about splat operator?

    RichardOnRails, Dec 29, 2010, in forum: Ruby
    Replies:
    8
    Views:
    108
    Ryan Davis
    Dec 30, 2010
Loading...

Share This Page