Martyn Lloyd-Kelly
Martyn Lloyd-Kelly

Reputation: 75

NetLogo: primitives or extension primitives to determine operating system?

I was curious as to whether or not anybody was aware of a built-in Netlogo or Netlogo extension primitive that allows you to determine the operating system that the user is currently running? I wish to alter directory separators according to the user's operating system and being able to determine this information would be incredibly useful.

If there isn't any such thing, I'll get to building it!

Upvotes: 1

Views: 139

Answers (1)

Seth Tisue
Seth Tisue

Reputation: 30498

No built-in primitive exists.

It would probably be possible to hack something kludgy together in pure NetLogo by using file-exists? to test for the presence or absence of certain OS-specific files, for example /etc/passwd.txt on Unix-like systems (including Mac OS X). As for the best files to use for this, I don't know, but it wouldn't surprise me if there was already an SO answer on this (since it isn't a NetLogo-specific question).

I thought maybe https://github.com/NetLogo/Shell-Extension/ had it. But I see now that it although it has primitives for reading and setting environment variables, it doesn't have similar primitives for Java system properties, which is what you need here (System.getProperty("os.name")). It would make a nice addition to the extension, I think.

re: "alter directory separators according to the user's operating system" specifically:

If you need to deal with paths that are coming from the operating system, then yeah, you need to be prepared to deal with platform-specific separators.

If you're only sending paths to the operating system, you may not need to worry about it. I haven't used Windows in a long time, but iirc it might just work to use forward slash.

If you're doing pathname manipulation, you'll probably want to check out Charles Staelin's pathdir extension, https://github.com/cstaelin/Pathdir-Extension. It includes a pathdir:get-separator primitive, as well as lots of other useful-looking stuff.

Upvotes: 1

Related Questions