Splat operator gives an SystemStackError

  • Thread starter Gunther Diemant
  • Start date
G

Gunther Diemant

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
 
J

Justin Collins

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
 
G

Gunther Diemant

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top