LogoUtils: Utility Functions for NetLogo 🧰

Hi everyone!

I’m excited to share my new NetLogo project: LogoUtils.

LogoUtils is a collection of procedures for common NetLogo programming tasks. The library includes tools for control flow, logic, defensive programming, file system operations, list manipulation, mathematical utilities, string handling, and world management.

Many of these procedures are planned for inclusion as NetLogo modules once this feature becomes available in future NetLogo releases. Until then, LogoUtils offers a convenient way to access these utilities.

How It Works

All procedures are found in the repository nls directory. Each function is provided in its own file named after the function, except for test, check, and assertion functions, which are grouped by category.

To use a procedure, copy its code into your model or import it using the __includes primitive.

Some functions depend on NetLogo extensions or other utility functions. Any required dependencies are listed in the file header.

Here are some examples:

Control Flow and Logic

Defensive Programming

File System

Lists

Mathematical

Strings

  • as-string (to-report): Converts any value to a string.
  • str-extract-all (to-report): Extracts all matches from a string using a regular expression. Returns a list of all matches found, with false for any non-matching elements.
  • str-replace-all (to-report): Replaces all matches in a string using a regular expression. Returns the string with all matches replaced, or the original string if no matches are found.

World

  • check-world-bleed (to-report): Checks a range of pxcor and pycor values to identify any lines of patches with a value of 0, false, or NaN. Returns a list containing two ordered lists: one with the pxcor values and one with the pycor values of patches that meet this condition. If no such patches are found, both lists are empty.
  • remove-world-bleed (to): Checks for and removes world bleed patches—lines of patches at the edges of the world with values of 0, false, or NaN.
  • show-values (to): A procedure for use with a forever button that displays patch values under the mouse cursor in the NetLogo view. Useful for interactively inspecting patch data during model runs.

Learn more at: GitHub - danielvartan/logoutils: 🧰 Utility Functions for NetLogo

GitHub Stars are always appreciated! :star:

Cheers,

Daniel Vartanian

3 Likes