R
Redson
I'm learning ruby on my own and going through the normal academic
examples to try and get started in this language.
While trying to do the simple "powerset" problem that's so easy in
lisp/ml, I run into either a "stack too deep" or an outright segfault,
which I didn't expect from ruby. I haven't been able to find anything
on google about it. I'm using ruby 1.8.4 on linux x86.
with the following code:
class Array
def powerset
if !self
return []
end
hd,*tl = self
tl.powerset.each do |i|
i + (i.push(hd))
end
end
end
I get:
irb(main):001:0> require 'setops.rb'
=> true
irb(main):002:0> [1,2].powerset
SystemStackError: stack level too deep
from ./setops.rb:30:in `powerset'
from ./setops.rb:30:in `powerset'
from (irb):2
examples to try and get started in this language.
While trying to do the simple "powerset" problem that's so easy in
lisp/ml, I run into either a "stack too deep" or an outright segfault,
which I didn't expect from ruby. I haven't been able to find anything
on google about it. I'm using ruby 1.8.4 on linux x86.
with the following code:
class Array
def powerset
if !self
return []
end
hd,*tl = self
tl.powerset.each do |i|
i + (i.push(hd))
end
end
end
I get:
irb(main):001:0> require 'setops.rb'
=> true
irb(main):002:0> [1,2].powerset
SystemStackError: stack level too deep
from ./setops.rb:30:in `powerset'
from ./setops.rb:30:in `powerset'
from (irb):2