title: counting how many times an agent appears in a list in netlogo ("expected a literal value" error)
body: <p>I'm trying to count the number of times an agent appears in a list in netlogo. I have a list of agents (it's an output from running draws of a multinomial distribution) and I want to save the number of times an agent appears in the output list. The output is not an agentset given that agents can appear multiple times within a list. The main error that I am running into is that when I try to filter the list, it says &quot;expected a literal value.&quot;</p>
  <p>Note: output is the name of the list and it is saved as a patch variable. For example, &quot;show output&quot; gives the following:
  (patch 0 0): [(turtle 44) (turtle 44) (turtle 6) (turtle 19) (turtle 33) (turtle 33)]
  Not every turtle appears in the list but some turtles appear multiple times.</p>
  <p>First, I tried the below code to get turtles to filter the output list to exclude non-self:</p>
  <pre><code>  ask turtles-here [      
    show filter [i -&gt; [i != who of myself]] [output]
    let output-me-only show filter [i -&gt; [i != who of myself]] [output] ;to create subsetted list
    set number-me-appears length [output-me-only] ;to save number of times the turtle appears in the original list (&quot;output&quot;)
    show number-me-appears
  ]
  </code></pre>
  <p>Because that didn't work, as it gave the &quot;expected a literal value&quot; error, I tried the below code:</p>
  <pre><code> ask turtles-here [       
    show filter [i -&gt; [i != self]] [output]
   ]
  </code></pre>
  <p>Both attempts resulted in the &quot;expected a literal value&quot; error.</p>
  <p>I thought the &quot;literal value&quot; error may be coming up because the list is made up of turtle IDs that are not simple numbers, but are also not recognized as agents given that it is not technically an agentset. I tried converting the list to literal ID numbers using the &quot;who&quot; primitive, but was not successful. See below:</p>
  <pre><code>  let converted-output []
    show map [ x -&gt; who] [output] 
    let converted-new-infections insert-item x
  </code></pre>
  <p>This did not work because of the &quot;expected a literal value&quot; again.</p>
  <p>Thank you for your help on this!</p>