Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

array assign to memo in reduce errors out #320

Closed
jhellerstein opened this issue Jul 29, 2013 · 1 comment
Closed

array assign to memo in reduce errors out #320

jhellerstein opened this issue Jul 29, 2013 · 1 comment
Assignees

Comments

@jhellerstein
Copy link
Member

(Courtesy Ben Sklaroff:)

The typical array-assignment syntax for ruby seems to cause errors within the block of a Bloom collection's reduce.

Given that the syntax seems to be perfectly legal Ruby, it's tempting to think that the bug may occur as a result of rewriting somewhere...

require 'rubygems'
require 'bud'

class Test
  include Bud

  state do
    table :a, [:idx]
  end

  bloom do
    a <= [[23], [47]]
    stdio <~ a.reduce({}) do |memo, t|
      memo[[0, 0, 'joe']] ||= 0
      # this works:
      memo[[0,0,'joe']] += 1
      # this doesn't work
      # memo[[0, 0, 'joe']] = memo[[0, 0, 'joe']] + 1
      # nor does the following
      memo[[0,1,'joe']] = 7
      memo
    end.inspected
  end

end

x = Test.new
x.tick
@ghost ghost assigned palvaro Jul 29, 2013
@neilconway
Copy link
Member

At first glance looks like a bug in either RubyParser or Ruby2Ruby:

require 'rubygems'
require 'ruby_parser'
require 'ruby2ruby'

src="a = [[23], [47]]
a.reduce({}) do |memo, t|
  memo[[0, 0, 'joe']] ||= 0
  memo[[0, 0, 'joe']] = memo[[0, 0, 'joe']] + 1
  memo
end
"

p = RubyParser.for_current_ruby
ast = p.parse(src)
new_src = Ruby2Ruby.new.process(ast)
puts new_src

Output:

a = [[23], [47]]
a.reduce({}) do |memo, t|
  memo[[0, 0, "joe"]] ||= 0
  memo[0, 0, "joe"] = (memo[[0, 0, "joe"]] + 1)
  memo
end

From looking at the AST it seems more likely to be a RubyParser bug. I'll file a ticket with the upstream folks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants