Search code examples
matrixdeclarenetlogo

How do I declare a global matrix in NETLOGO? (Using matrix extension)


I found an example using the following sintax:

let A matrix: from-row-list [[3 5] [0 1]]
let B matrix: from-row-list [[3 0] [5 1]]

But it keeps showing: Expected keyword. It selects the let reserved word. Thanks.


Solution

  • let defines a variable that's local to a procedure or other embedded context, and it generates that error if used at the top level. I guess that let doesn't count as a "keyword" in that context.

    To define a global matrix, specify the variable name in globals, and then set it inside a procedure:

    extensions [matrix]
    
    globals [A B]
    
    to setup
      set A matrix:from-row-list [[3 5] [0 1]]
      set B matrix:from-row-list [[3 0] [5 1]]
    end
    

    Then add a button that calls setup. Note that you need to remove the space after "matrix:"