Hello Rafaela,
Let's start with question 2. What you want here is the sublist primitive. The following procedure will report the last num elements of a list, lst, or, if there are fewer than n elements in the list, the whole list.
to-report get-last [num lst]
let b length lst
let a b - num
report sublist lst (ifelse-value (a < 0) [0] [a]) b
end
observer> show get-last 3 [1 2 3 4 5]
observer: [3 4 5]
observer> show get-last 6 [1 2 3 4 5]
observer: [1 2 3 4 5]
observer> show get-last 3 []
observer: []
As for your first question, In
if these two commands really follow each other, you are first making patch-visited a one element list, so it might look like [(patch 0, 1)], and then adding it to itself, getting something like [(patch 0, 1) (patch 0, 1)]. Putting that aside, however, the last primitive will pull out the last element of that list, (patch 0, 1), which is a patch, not a list. member?, however, looks for elements in a list so it gives you that error if, instead of looking in a list of patches, it is looking at a single patch. What you want to do is compare self, a patch, with the last element in patch-visited, a patch, using !=.
let availablePatch neighbors with [ self != [ last patch-visited ] of myself ]
Or, you could put both your questions together and use
let availablePatch neighbors with [not member? self [get-last 1 patch-visited] of myself]
Since get-last returns a list of patches, even if it contains only a single patch, member? will work on it. And if you want to exclude, say the three most recent patches, simply replace 1 by 3.
Hope this helps,
Charles
-------------------------------
Charles P. StaelinProfessor Emeritus of Economics
Smith College
Northampton, MA 01063