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
any-member?(to-report): Tests if any element in a list is a member of another list.any-true?(to-report): Tests if any element in a list istrue.list-any?(to-report): Tests if any element in a list is equal to a specified value or to values in another list.
Defensive Programming
assert-atomic?(to): Asserts that a value is not a list.assert-between?(to): Asserts whether a value is equal or between two numbers.assert-choice(to): Asserts whether a value is one of a set of choices.
File System
file-path(to-report): Creates a file path from a directory and a file name.list-files-by-pattern(to-report): Lists files in a directory that match a specified pattern.normalize-path(to-report): Normalizes a file path making it compatible with the user operating system.
Lists
as-list(to-report): Converts an atomic value to a list.collapse(to-report): Collapses a list into a string using a separator (e.g.,[1 2 3 4]→"1, 2, 3, 4").combine(to-report): Combines two lists into a single list.
Mathematical
distance-between(to-report): Returns the distance between two numbers.random-beta(to-report): Returns a random number from a beta distribution with parametersalphaandbeta.rescale(to-report): Rescales a number from one range to another.
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, withfalsefor 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 ofpxcorandpycorvalues to identify any lines of patches with a value of0,false, orNaN. Returns a list containing two ordered lists: one with thepxcorvalues and one with thepycorvalues 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 of0,false, orNaN.show-values(to): A procedure for use with aforeverbutton 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! ![]()
Cheers,
Daniel Vartanian