Affect of CAREFULLY on MYSELF

26 views
Skip to first unread message

James Steiner

unread,
Jun 9, 2022, 2:02:12 PM6/9/22
to netlogo-users, netlog...@googlegroups.com
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?

Seth Tisue

unread,
Jun 9, 2022, 3:28:38 PM6/9/22
to netlogo-devel
Seems like a bug to me. I don't think we designed it that way.

jeremy...@northwestern.edu

unread,
Jun 10, 2022, 3:51:44 PM6/10/22
to netlogo-devel
It turns out this was previously reported, albeit in a different way using `other-end`:  https://github.com/NetLogo/NetLogo/issues/1345

Roberts comment there lays it out pretty clearly:

>  The problem (in NetLogo terms) is that myself is incorrectly set to self within carefully (and the implementation of other-end uses myself). 

He goes on to elaborate on the technical issues.  

I added a slimmed down version of this code there as a language test we could add to NetLogo to help work the issue.

-Jeremy

Uri Wilensky

unread,
Jun 10, 2022, 4:21:11 PM6/10/22
to Baker Jeremy, netlogo-devel
Thanks Jeremy.
This bug seems reasonably high priority to me.


—Uri


Uri Wilensky
Lorraine H. Morton chaired Professor 
Professor of Learning Sciences, Computer Science and Complex Systems
Director, Center for Connected Learning  and Computer-Based Modeling (CCL)
Northwestern University





--
You received this message because you are subscribed to the Google Groups "netlogo-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-deve...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-devel/67a2bc89-8c0c-419d-beb7-baaa80924794n%40googlegroups.com.

Jeremy Baker

unread,
Jun 10, 2022, 4:26:24 PM6/10/22
to Uri Wilensky, netlogo-devel
I definitely agree it should be fixed, but I don't think I would call it high priority.  It only affects the use of two prims (`myself` and `other-end`) when used inside of `carefully`.  To me that seems pretty unlikely to trip anyone up; few people use `carefully` at all.  We've had two reports about it, one it 2017, and obviously this one in 2022, both from "advanced" NetLogo users, so it doesn't seem to be causing too much trouble.  Just to check, I ran it in NetLogo 5.3.1 and it was a problem there, too, so it's even older than 2017.

-Jeremy


From: Uri Wilensky <uri.wi...@gmail.com> on behalf of Uri Wilensky <u...@northwestern.edu>
Sent: Friday, June 10, 2022 3:21 PM
To: Jeremy Baker <jeremy...@northwestern.edu>
Cc: netlogo-devel <netlog...@googlegroups.com>
Subject: Re: [netlogo-devel] Affect of CAREFULLY on MYSELF
 
You received this message because you are subscribed to a topic in the Google Groups "netlogo-devel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/netlogo-devel/8gRKO-Q9q44/unsubscribe.
To unsubscribe from this group and all its topics, send an email to netlogo-deve...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-devel/91463E15-DFDE-46E7-A1C6-809990911265%40northwestern.edu.

John Chen

unread,
Jun 10, 2022, 4:28:07 PM6/10/22
to Jeremy Baker, Uri Wilensky, netlogo-devel
I do see children using carefully but probably not combined with myself. 

John

James Steiner

unread,
Jun 10, 2022, 5:39:08 PM6/10/22
to John Chen, Jeremy Baker, Uri Wilensky, netlogo-devel
It’s true I only stumbled on it because I was playing with an otherwise also deliberately incorrect piece of code. 

([ myself ] of myself) which does not reach backward up the context layers, but as it should, creates a new inner context.)

Reply all
Reply to author
Forward
0 new messages