I have a list of lists. I am trying to filter based on an element in the inner list and compare it to time so that the code performs only on that temporary list. Here is the outer list.
observer> show edge-list
observer: [[18927 8 9] [18984 13 14] [18985 14 15] [18985 15 16] [18993 13 30]
I would like to pull out the 18985 and compare it to the current-time global variable within a loop. If it matches, it needs to pull all the lists with 18985 in the first element. My code so far is :
to load-edges
; filter edges that match the current tick
let current-edges filter [ inner-list ->
item 0 inner-list = current-time] edge-list
foreach current-edges [
let source-n item 1 current-edges
let target-n item 2 current-edges
; Ensure turtles exist for the source and target
if any? nodes with [who = source-n] [
let source-node one-of nodes with [who = source-n]
let target-node one-of nodes with [who = target-n]
ask source-node [
create-link-with target-node [
set color grey ]
]
]
]
end
I am getting this runtime error
Can't find element 1 of the list [[18985 14 15]], which is only of length 1.
error while observer running ITEM
called by (anonymous command: [ let source-n item 1 current-edges let target-n item 2 current-edges if any? nodes with [ who = source-n ] [ let source-node one-of nodes with [ who = source-n ] let target-node one-of nodes with [ who = target-n ] ask source-node [ create-link-with target-node [ set color grey ] ] ] ])
called by procedure LOAD-EDGES
It seems like it is accessing the first list in the outer list, but not by the first element of the inner list. (18985). Current-edges needs to a list of the 2 lists with 18985. then for each list in current-edges, I need to assign the source and target nodes and create an edge.
When I ask to show current-edge in the command center- it states there is nothing named current-edges. Did I use filter wrong?
Thank you!