buzz_syntax_cheatsheet

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revisionBoth sides next revision
buzz_syntax_cheatsheet [2016/04/09 21:34] rootbuzz_syntax_cheatsheet [2016/09/02 20:27] ilpincy
Line 2: Line 2:
  
 ^ Category ^ Examples ^ ^ Category ^ Examples ^
-^ Comments | <code># This is a comment</code>+^ Comments | <code buzz># This is a comment</code>
-^ File inclusion | <code>include "otherfile.bzz"</code>+^ File inclusion | <code buzz>include "otherfile.bzz" 
-^ Variables | <code># assignment (by default variables are global)+ 
 +# NOTE: A specific file can be included only once. 
 +# Any 'include' statement for a file is ignored after the first inclusion 
 +# occurred. 
 +# Relative paths are automatically transformed into absolute paths before 
 +# including a file.</code>
 +^ Variables | <code buzz># assignment (by default variables are global)
 x = 2.55   # number x = 2.55   # number
 x = "ciao" # string x = "ciao" # string
Line 16: Line 22:
 # printing on the ARGoS logger # printing on the ARGoS logger
 log("INFO: x = " , x)</code> | log("INFO: x = " , x)</code> |
-^ Conditionals | <code># simple if/then+^ Conditionals | <code buzz># simple if/then
 if (x > 3) { if (x > 3) {
    log("x is too big")    log("x is too big")
Line 48: Line 54:
 if (not (x < 3)) if (not (x < 3))
    log("x is <= 3")</code> |    log("x is <= 3")</code> |
-^ Loops |<code># 'while' loop to print 1 2 3 4 5+^ Loops |<code buzz># 'while' loop to print 1 2 3 4 5
 x = 0 x = 0
 while (x < 5) { while (x < 5) {
Line 54: Line 60:
    log(x)    log(x)
 }</code> | }</code> |
-^ Tables |<code># creating an empty table+^ Tables |<code buzz># creating an empty table
 t = {} t = {}
  
Line 94: Line 100:
 # prints the number of elements in a # prints the number of elements in a
 log(size(a))</code> | log(size(a))</code> |
-^ Functions |<code># defining a function+^ Functions |<code buzz># defining a function
 function my_fun(p) { function my_fun(p) {
    log("Called my_fun(", p, ")")    log("Called my_fun(", p, ")")
Line 105: Line 111:
  
 # creating a lambda # creating a lambda
-= function(a, b) {+lambda = function(a, b) {
    return a + b    return a + b
-}</code>+} 
-^ Math |<code># all the math functions are part of the 'math' table+lambda(1,2)</code>
 +^ Math |<code buzz># all the math functions are part of the 'math' table
  
 # setting a 2D vector from length and angle # setting a 2D vector from length and angle
Line 125: 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, v2) vec2_sum(v1, v2)
  
Line 133: Line 140:
    return math.atan2(v.y, v.x)    return math.atan2(v.y, v.x)
 }</code> | }</code> |
-^ Swarm management |<code># creation of a swarm with identifier 1+^ Swarm management |<code buzz># creation of a swarm with identifier 1
 s = swarm.create(1) s = swarm.create(1)
  
Line 170: 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)</code> | n = s.others(103)</code> |
-^ Neighbor management | <code># Iteration (rid is the neighbor's id)+^ Neighbor management | <code buzz># Iteration (rid is the neighbor's id)
 neighbors.foreach( neighbors.foreach(
   function(rid, data) {   function(rid, data) {
     log("robot ", rid, ": ",     log("robot ", rid, ": ",
-        "distance  = ", data.distance, ", " +        "distance  = ", data.distance, ", ", 
-        "azimuth   = ", data.azimuth, ", "+        "azimuth   = ", data.azimuth, ", ",
         "elevation = ", data.elevation) })         "elevation = ", data.elevation) })
  
Line 187: 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 196: 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 215: Line 223:
 # Broadcasting a (key,value) pair # Broadcasting a (key,value) pair
 neighbors.broadcast("key", value)</code> | neighbors.broadcast("key", value)</code> |
-^ Virtual stigmergy | <code># Create a new virtual stigmergy+^ Virtual stigmergy | <code buzz># Create a new 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)
  • buzz_syntax_cheatsheet.txt
  • Last modified: 2018/03/23 18:17
  • by jayam