buzz-lang/Buzz

intersection, union, difference, others

Closed this issue · 3 comments

Creating swarm with these functions, there are data type errors.

screenshot from 2018-06-06 13-21-51

Can you please post the offending code and your expected result?

Set operations within the swarm construct terminate with "type mismatch: expected table, got integer".
I am attaching a minimalistic script that leads to a crash and the error message.
Buzz Script:

# Executed at init time
function init() {
  a = swarm.create(2)
  b = swarm.create(3)
  a.select(id%2==0)
  b.join()
 }
# Executed every time step
function step() {
 a.exec(function() { log("[",id,"]","Swarm a") })
 b.exec(function() { log("[",id,"]","Swarm b") })
 i = swarm.intersection(100, a, b)
}
# Executed once when the robot (or the simulator) is reset.
function reset() {
}
# Execute at exit
function destroy() {
}

Error message:


[ROBOT 0] ../../build/testing/swarm_test.bo: execution terminated abnormally: /home/vivek/custom_software/buzz/Buzz/build/testing/swarm_test.bzz:14:33: type mismatch: expected table, got integer

============================================================
state: error	error: 6
code size: 428	oldpc: 354	pc: 354
stacks: 2	cur: 1
cur instr: gstore
next instr: gstore
	3	[table] 7 elements
			[string] 93:'others' -> [c-closure] 93
			[string] 94:'leave' -> [c-closure] 95
			[string] 95:'in' -> [c-closure] 96
			[string] 5:'select' -> [c-closure] 97
			[string] 6:'id' -> [int] 100
			[string] 7:'join' -> [c-closure] 94
			[string] 9:'exec' -> [c-closure] 98

	2	[string] 15:'i'
	1	[nil]
	0	[nil]
============================================================

============================================================
state: error	error: 6
code size: 428	oldpc: 354	pc: 354
stacks: 2	cur: 2
cur instr: gstore
next instr: gstore
	0	[int] 147
============================================================

Thanks, Vivek for posting the code.