flat_map

1 view
Skip to first unread message

Yoriyasu Yano

unread,
Nov 26, 2011, 5:05:16 PM11/26/11
to program...@googlegroups.com
Hey,

I noticed that flat_map on a bloom collection will cause it to cycle through the collection twice (demonstrated in pasted code below).
Is this intentional?

CODE:
class B
  include Bud

  state do
    scratch :t, [:a, :d]
    scratch :b, [:a, :dp]
  end

  bloom :test do
    b <= t.flat_map do |p|
      puts p.inspect
      p.d.map {|g| [p.a, g]}
    end
  end
end
b = B.new
b.t <+ [[1, [["a", "a"], ["b", "b"]]]]
b.tick

OUTPUT:
[1, [["a", "a"], ["b", "b"]]]
[1, [["a", "a"], ["b", "b"]]]

--
Yoriyasu Yano
University of California, Berkeley
BA Cognitive Science and Computer Science

Joseph Hellerstein

unread,
Nov 27, 2011, 2:14:02 AM11/27/11
to program...@googlegroups.com
In general, rule bodies may be eval'ed many times per tick, so side-effects in rule bodies are not a good idea!

Note that BudCollections have set semantics, so eval'ing the rhs multiple times per tick shouldn't affect the lhs (unless you do side-effecting stuff in bodies!)

In future versions of Bud, side-effects in the body will be forbidden...

J

Reply all
Reply to author
Forward
0 new messages