passing arguments to procedures

15 views
Skip to first unread message

Geoff Dougherty

unread,
Jul 18, 2024, 1:08:58 PM (4 days ago) Jul 18
to netlogo-users
Hi, 

I have code that includes similar but separate procedures for a bunch of related tasks. I am looking to create a single procedure that can be called in a loop. 

Right now it looks like this: 

to measure-10k
   set result-10k end-10k - start-10k
end

to measure-5k
   set result-5k end-5k - start-5k
end

ask turtles [ measure-10k ]
ask turtles [ measure-5k ]

I would like to get to something that looks (in non-functional pseudocode) like: 

to measure [race]
    set result-race end-race - start-race
end

foreach [5k 10k] [race -> ask turtles measure [race ]]
 
Any thoughts on how to do something like this? 

jason.b...@gmail.com

unread,
Jul 18, 2024, 4:59:31 PM (4 days ago) Jul 18
to netlogo-users
What are `end-10k` and the related terms?  Are they defined in `globals`?  In a `turtles-own`?  The code you've provided suggests that they are specific to the turtles, but then that makes the idea of iterating over the races in a loop seem less helpful.

And what do you want to happen with `result-race`?  In your pseudocode, it is written once for the 10K races, and then immediately overwritten for the 5K races.

Are the races dynamic in some way?  (That is: Do you not know for certain that there will be a 10K and a 5K?)  If you always have the same races, it seems to me like it would good to simply do:

```
to measure
  set result-10k (end-10k - start-10k)
  set result-5k  (end-5k  - start-5k)
end


ask turtles [measure]
```

Jason Bertsche
Reply all
Reply to author
Forward
0 new messages