Simon Bush
Simon Bush

Reputation: 407

how to use the netlogo anonymous -> in this case

I am having trouble converting an old 5.3.1 task to the an anonymous procedure used in 6.01. Any help would be greatly appreciated.

The line I am having trouble with is the following:

>let most-efficient? task [first ? = lowest-first]

Here it is in the context of the full reporter:

> to-report best-route [route-list]  ;; [a list of network sections]                                         
> let lowest-first min map first route-list
> let most-efficient? task [first ? = lowest-first]  
> let best-route first butfirst one-of filter most-efficient? route-list  
> report best-route                  
> end

The original code was provided by Seth T.

Regards

Simon

Upvotes: 0

Views: 335

Answers (1)

Bryan Head
Bryan Head

Reputation: 12580

First, the task primitive no longer exists. Second, instead of using ?, you now provide an argument to the primitive using the -> syntax.

In this case, that looks like:

let most-efficient? [route -> first route = lowest-first]

Here, we're using an argument route in the anonymous procedure. route will be used in the same way ? would've been in the old task syntax.

Note that for two or more arguments, you need to surround them by [] to group them together:

let add [ [ x y ] -> x + y ]

Edit: Forgot to link to the programming guide section on anonymous procedures! It contains the full details:

https://ccl.northwestern.edu/netlogo/docs/programming.html#anonymous-procedures

Upvotes: 3

Related Questions