I was trying something unusual, and *just* noticed that MYSELF has an unexpected (to me) behavior when used inside a CAREFULLY block, and this behavior is not called out in the Primitives Dictionary. Maybe one of the NetLogo books mentions it.
It seems that NetLogo CAREFULLY creates a new "inner" agent execution context, so that MYSELF points to "the agent that asked this agent to run this code", or in other words, the same agent running CAREFULLY
Here is the output of a test:
observer> test-myself
(patch -24 -14): "self is(patch -24 -14)"
(patch -24 -14): "carefully myself is (patch -24 -14)" (Note: I THINK THIS SHOULD THROW AN ERROR, IT DOESN'T)
(turtle 0): "self is(turtle 0)"
(turtle 0): "myself is (patch -24 -14)"
(turtle 0): "carefully myself is (turtle 0)"
(turtle 1): "self is(turtle 1)"
(turtle 1): "myself is (turtle 0)"
(turtle 1): "carefully myself is (turtle 1)"
(link 0 1): "self is(link 0 1)"
(link 0 1): "myself is (turtle 1)"
(link 0 1): "carefully myself is (link 0 1)"
Here is the code of that test:
to id
show (word "self is" self)
end
to id-myself
let $myself "undefined"
set $myself myself
show (word "myself is " $myself)
end
to id-myself-carefully
let $myself "undefined"
carefully [ set $myself myself ][]
;; running in the observer context, I think this should throw an error
;; leaving $myself with a value of "undefined." It doesn't.
show (word "carefully myself is " $myself)
end
to test-myself
clear-all
ask patch min-pxcor min-pycor
[ id
id-myself-carefully
sprout 1
[ id
id-myself
id-myself-carefully
hatch 1
[ id
id-myself
id-myself-carefully
create-link-with myself
[ id
id-myself
id-myself-carefully
]
]
]
]
end
Thoughts?