5

I downloaded the modified random clusters code for generating neutral landscape models using the Millington's version of the modified random clusters approach in the NetLogo modeling commons. When I click the "generate-landscape" button, the "fill-landscape" procedure in the code causes a "Nothing named ? has been defined" error.

When I created the attached interface image and attempted to run the adjoining code below. The problem seems to be related to the question mark in the "occurrences" report function. The reduce function is not working as intended. Is there a work around for this? See interface, then code below:enter image description here

  ifelse ( any? neighbours with [ cluster != nobody ] )  ;; check if there are any assigned patches in neighbourhood
  [

    let covers []

    ask neighbours with [ cluster != nobody ]
    [
      set covers fput cover covers    ;;ask neighbours to add their covers to the list
    ]

    let unique-covers remove-duplicates covers    ;;create a list of unique covers

    let max-cover-count -1                 ;the number of neighbours with the maximum cover
    let max-cover -1                       ;the maximum cover

    ifelse(length unique-covers > 1)
    [
      ;if there is more than one unique-cover
      foreach unique-covers                  ;for each of the unique covers
      [
        let occ occurrences ? covers          ;count how many neighbours had this cover

        ifelse(occ > max-cover-count)        ;if the count is greater than the current maximum count
        [ 
          set max-cover ?                    ;set this as the dominant cover
          set max-cover-count occ            ;update the current maximum count

;---------------

to-report occurrences [x the-list]
  report reduce
    [ifelse-value (?2 = x) [?1 + 1] [?1]] (fput 0 the-list)
end 
;---------------    

The code is suppose to generate a neutral landscape model using the modified random clusters approach developed by Saura and Martinez-Millan (2000). However, the error "Nothing named ? has been defined" error the code from running smoothly. Looking forward to thoughts ...

nigus21
  • 337
  • 2
  • 11

2 Answers2

6

The old ? syntax from NetLogo 5.x was replaced with the new -> syntax in NetLogo 6. See https://ccl.northwestern.edu/netlogo/docs/programming.html#anonymous-procedures

So, for example, in NetLogo 5, you would write:

foreach [0 1 2 3] [
  print ?
]

in NetLogo 6, you write:

foreach [0 1 2 3] [ x ->
  print x
]
Bryan Head
  • 12,360
  • 5
  • 32
  • 50
  • So how would you rewrite the sections with "?" in my code, if I may ask? – nigus21 Feb 02 '19 at 02:08
  • Please edit your question so that only the relevant procedures are shown – JenB Feb 02 '19 at 17:37
  • @JenB I have edited the question leaving only the relevant procedure. I look forward to your thoughts. – nigus21 Feb 02 '19 at 18:56
  • I still can't see it sorry. I can see that the 'occurrences' procedure needs revision, but I can't see anything in the long procedure. Can you just do the section that needs it maybe? – JenB Feb 03 '19 at 09:45
  • @JenB I have removed the sections of the "fill-landscape" procedure that do not have "?" in them so that only lines directly related to "?" show. I look forward to your thoughts. – nigus21 Feb 03 '19 at 15:30
  • @JenB Thanks a million. One more thing for the subsequent lines in procedure `if(occ = max-cover-count) ;otherwise, if the count is equal to the current maximum count [ let rand random-float 1 if(rand < 0.5) [ set max-cover ? ] ;randomly pick one of the two covers to be the new dominant cover ]` where there is a "?" in the if statement, based on the logic of your edits, should I set that to the "this-cover" variable you created? – nigus21 Feb 04 '19 at 19:53
3

A combination of Bryan's answer (first procedure) and the NetLogo Dictionary (second procedure) gives you the following. The comments indicate the new bits. Not tested.

ifelse ( any? neighbours with [ cluster != nobody ] )
[ let covers []
  ask neighbours with [ cluster != nobody ]
  [ set covers fput cover covers
  ]
  let unique-covers remove-duplicates covers
  let max-cover-count - 1  ; added a space around subtraction
  let max-cover - 1        ; more spacing
  ifelse(length unique-covers > 1)
  [ foreach unique-covers
    [ this-cover ->                  ; here's the new bit, calling ? 'this-cover'
      let occ occurrences this-cover covers ; passes to the occurrences procedure
      ifelse(occ > max-cover-count)
      [ set max-cover this-cover     ; using the name this-cover again
        set max-cover-count occ

And for occurrences, you can take the procedure directly from the NetLogo Dictionary reduce example

to-report occurrences [#x #the-list]
  report reduce
    [ [occurrence-count next-item] -> ifelse-value (next-item = #x)
        [occurrence-count + 1] [occurrence-count] ] (fput 0 #the-list)
end
JenB
  • 17,620
  • 2
  • 17
  • 45