NetLogo: Use variable not literal to index lists or arrays?

Viewed 22

I am trying to port this pseudocode into NetLogo, and finding it difficult because NetLogo requires a literal to be used as a list index, rather than allowing a variable containing the index value (such as index in the code below) to be used. I tried the array extension, and it likewise doesn't allow a variable to be used for an array index.

Basically, my goal is to

  1. identify elements that differ in the lists of two agents
  2. randomly select one of the elements that will change for both agents.

Any ideas of how to do this in NetLogo?

; Have an agent interact with some another culture if they
; are similar enough that the agent accepts the influence
; and if the event passes some degree of randomness. In
; ’ jump ’ mode we take the exact culture value of the other
; culture , in ’ shift ’ mode we shift closer to that culture. 
function interactWith Culture ( agent , other_culture ) {
  similarity = calculateSimilarity ( agent. culture , other_culture )
  chance = uniform Random ( min = 0 , max = 1)

  if ( similarity > minimum_similarity and chance < similarity ) { 
    index = findDifferingElement (agent. culture , other_culture )
    if ( interaction_method == ’ jump ’) {
       agent. culture[ index ] = other_culture [ index ]
    } else {
       difference = agent. culture[ index ] - other_culture [ index ]
       agent. culture[ index ] = agent. culture[ index ] - 
                                 difference * shift_degree
    }
  }
}
0 Answers
Related