Netlogo 使用两个参数筛选所有列表

Netlogo 使用两个参数筛选所有列表,netlogo,Netlogo,根据一位用户对这个问题的回答:,我尝试使用他建议的方法来过滤物品和海龟,如下所示: show sum map [t -> length filter [a -> item 1 a = turtle 3] [ all-archives ]] of all-turtles 上面的代码应该计算由海龟3创建的项目1被包括在所有海龟(所有海龟)的列表(所有档案)中的次数。 但是,我从上面的公式中得到以下错误: 错误:应为右括号 (在第二个“a”处) 我确信在我写的东西中仍然存在语法错误,但

根据一位用户对这个问题的回答:,我尝试使用他建议的方法来过滤物品和海龟,如下所示:

show sum map [t -> length filter [a -> item 1 a = turtle 3] [ all-archives ]] of all-turtles 
上面的代码应该计算由
海龟3
创建的
项目1
被包括在所有海龟(
所有海龟
)的列表(
所有档案
)中的次数。 但是,我从上面的公式中得到以下错误:

错误:应为右括号

(在第二个“a”处)


我确信在我写的东西中仍然存在语法错误,但我没有发现任何使用两个参数进行过滤的示例

您确实有一个错位的
]
。有时更容易将这些长命令分解为多个部分。下面的代码设置了一个测试,让两个海龟将两个条目放在给定数量的其他海龟档案中,以及它们自己的档案中。然后,它以片段为单位进行计数,最后在一个命令中将这些片段放在一起。在您的问题中,您使用了“所有海龟”,但这只是NetLogo中的
turtles
。最后一个命令只查看海龟的随机子集

turtles-own [ archive ]

to test
  clear-all
  create-turtles 100 [
    set archive []
  ]

  ask turtle 3 [
    let archive-entry list "at home" self
    set archive fput archive-entry archive
    ask n-of 30 other turtles [ set archive fput archive-entry archive ]
    set archive-entry list "not at home" self
    set archive fput archive-entry archive
    ask n-of 40 other turtles [ set archive fput archive-entry archive ]
  ]

   ask turtle 4 [
    let archive-entry list "at home" self
    set archive fput archive-entry archive
    ask n-of 20 other turtles [ set archive fput archive-entry archive ]
    set archive-entry list "not at home" self
    set archive fput archive-entry archive
    ask n-of 50 other turtles [ set archive fput archive-entry archive ]
  ] 
  ; get a list of all archives.
  let list-of-all-archives [archive] of turtles
  ; make a list of the number of occurrences we are looking for in each archive.
  let list-of-count-in-each-archive map [t -> length filter [a -> item 0 a = "at home" and item 1 a = turtle 3] t] list-of-all-archives
  ; sum up the number of occurences across all archives.
  show sum list-of-count-in-each-archive

  show sum map [t -> length filter [a -> item 0 a = "not at home" and item 1 a = turtle 3] t] [archive] of turtles
  show sum map [t -> length filter [a -> item 0 a = "at home" and item 1 a = turtle 4] t] [archive] of turtles
  show sum map [t -> length filter [a -> item 0 a = "not at home" and item 1 a = turtle 4] t] [archive] of turtles

  show sum map [t -> length filter [a -> item 0 a = "not at home" and item 1 a = turtle 4] t] [archive] of n-of 50 turtles
end