Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| buzz_syntax_cheatsheet [2016/04/09 22:00] – root | buzz_syntax_cheatsheet [2018/03/23 18:17] (current) – jayam | ||
|---|---|---|---|
| Line 5: | Line 5: | ||
| ^ File inclusion | <code buzz> | ^ File inclusion | <code buzz> | ||
| - | # NOTE: A specific file can be included only once. Any ' | + | # NOTE: A specific file can be included only once. |
| - | ^ Variables | < | + | # Any ' |
| + | # occurred. | ||
| + | # Relative paths are automatically transformed into absolute paths before | ||
| + | # including a file.</ | ||
| + | ^ Variables | < | ||
| x = 2.55 # number | x = 2.55 # number | ||
| x = " | x = " | ||
| Line 18: | Line 22: | ||
| # printing on the ARGoS logger | # printing on the ARGoS logger | ||
| log(" | log(" | ||
| - | ^ Conditionals | < | + | ^ Conditionals | < |
| if (x > 3) { | if (x > 3) { | ||
| | | ||
| Line 50: | Line 54: | ||
| if (not (x < 3)) | if (not (x < 3)) | ||
| | | ||
| - | ^ Loops |< | + | ^ Loops |< |
| x = 0 | x = 0 | ||
| while (x < 5) { | while (x < 5) { | ||
| Line 56: | Line 60: | ||
| | | ||
| }</ | }</ | ||
| - | ^ Tables |< | + | ^ Tables |< |
| t = {} | t = {} | ||
| Line 96: | Line 100: | ||
| # prints the number of elements in a | # prints the number of elements in a | ||
| log(size(a))</ | log(size(a))</ | ||
| - | ^ Functions |< | + | ^ Functions |< |
| function my_fun(p) { | function my_fun(p) { | ||
| | | ||
| Line 107: | Line 111: | ||
| # creating a lambda | # creating a lambda | ||
| - | f = function(a, b) { | + | lambda |
| | | ||
| - | }</ | + | } |
| - | ^ Math |< | + | lambda(1,2)</ |
| + | ^ Math |< | ||
| # setting a 2D vector from length and angle | # setting a 2D vector from length and angle | ||
| Line 127: | Line 132: | ||
| v1.y = v1.y + v2.y | v1.y = v1.y + v2.y | ||
| } | } | ||
| - | v1 = { x=1, y=2 } | + | v1 = { .x=1, .y=2 } |
| - | v2 = { x=3, y=1 } | + | v2 = { .x=3, .y=1 } |
| vec2_sum(v1, | vec2_sum(v1, | ||
| # Getting the angle of a 2D vector | # Getting the angle of a 2D vector | ||
| function vec2_angle(v) { | function vec2_angle(v) { | ||
| - | | + | |
| }</ | }</ | ||
| - | ^ Swarm management |< | + | ^ Swarm management |< |
| s = swarm.create(1) | s = swarm.create(1) | ||
| Line 172: | Line 177: | ||
| # Create a new swarm n as the negation of swarm s | # Create a new swarm n as the negation of swarm s | ||
| n = s.others(103)</ | n = s.others(103)</ | ||
| - | ^ Neighbor management | < | + | ^ Neighbor management | < |
| neighbors.foreach( | neighbors.foreach( | ||
| function(rid, | function(rid, | ||
| log(" | log(" | ||
| - | " | + | " |
| - | " | + | " |
| " | " | ||
| Line 189: | Line 194: | ||
| math.sin(data.azimuth) | math.sin(data.azimuth) | ||
| c.z = data.distance * math.sin(data.elevation) | c.z = data.distance * math.sin(data.elevation) | ||
| - | return c }) | + | return c |
| + | | ||
| # Reduction (accum is a table) | # Reduction (accum is a table) | ||
| Line 198: | Line 204: | ||
| accum.z = accum.z + data.z | accum.z = accum.z + data.z | ||
| return accum | return accum | ||
| - | }, {x=0, y=0, z=0}) | + | }, {.x=0, .y=0, .z=0}) |
| # Filtering | # Filtering | ||
| Line 217: | Line 223: | ||
| # Broadcasting a (key,value) pair | # Broadcasting a (key,value) pair | ||
| neighbors.broadcast(" | neighbors.broadcast(" | ||
| - | ^ Virtual stigmergy | < | + | ^ Virtual stigmergy | < |
| # A unique id (1 here) must be passed | # A unique id (1 here) must be passed | ||
| v = stigmergy.create(1) | v = stigmergy.create(1) | ||