More list operations please!

I’ve developed a bunch of list utilities in a list-utils.nls file which you can check out in this repository. I found myself using many of these operations so often that it made sense for me to make these. As a regular user of R and Python I was finding NetLogo’s list operations a little bit limited and much as I enjoy figuring out map and reduceoperations, it made sense to replicate many R and Python list functions in this way.

I note that @danielvartan has also made utility functions — I don’t know if we should compare notes or join forces, or…?

I wonder if any of the procedures are worthy of inclusion as native reporters? Somewhere along the way range became a primitive, how about adding some more?!

For quick reference, here’s what my .nlsfile provides:

And these, which assume ordered lists, which can be maintained by only using these reporters to maintain lists:

Most of these should be self-explanatory. Many of them are trivial one or two liners using map and reduce but the latter in particular is not for the faint-hearted, and I think many of these might be nice to have!

I also have utilities for probability distributions not native in NetLogo. Any of these could be generated using R extensions, but it’s handy to have them native. I won’t clutter this post further with the details. See the documentation for details. random-binomial n p in particular would be nice to have native.

Great tools, thanks for sharing!

These could eventually become a NetLogo Module. Seth Tisue would probably argue they should be modularized, in the interest of keeping the language small.

My own default is usually to avoid adding new primitives to the core language. We have a module system that we’re aiming to release in the coming months (discussed a bit in the Modularity thread), and we’d love to see this file listed in the in-app library manager when that functionality is ready.

Nice work! :smiling_face_with_sunglasses: :+1:

That’s fair - the core language is already rather large, when compared to say Python. If you look at my repo you’ll see I’ve also made a vague attempt at adding string operations. I think list, string, and probability distribution modules would all be good additions, and I’d be happy to contribute to those as they develop.

I think these are great, David, and I agree with Jason that this is exactly the kind of code we’d want to see in a shared module once that work is complete. Thank you for posting them.

For anyone who lands here looking for such primitives, I just want to call out two extensions that already provide some functionality along these lines. They’re both supported in NetLogo Web as well.

-Jeremy

2 Likes