Skip to content

Conversation

@kgmt0
Copy link
Contributor

@kgmt0 kgmt0 commented Apr 19, 2025

This is still work-in-progress, but you can use it to load NLS files now. The alias option that allows you to control how names are prefixed is also working.

@ERSUCC
Copy link
Contributor

ERSUCC commented Apr 19, 2025

Do you have documentation or a sample model to demonstrate the new syntax?

EDIT: Never mind, I figured it out from the test cases you wrote.

@ERSUCC
Copy link
Contributor

ERSUCC commented Apr 19, 2025

@kgmt0 I played around with it for a bit, and so far I like the way it works and it seems very promising! Here are some issues I noticed:

  1. If you import a library and then just use its name without the colon and a command after it, the error message is "Nothing named xyz has been defined." I would expect it to be something along the lines of "xyz is a library, not a command."
  2. Imported libraries don't show up under the Included Files dropdown. This is probably up for debate but personally I would like it if they showed up there so I could easily open them.
  3. alias is used like a keyword as far as I can tell, but the compiler does not identify it as a keyword. This means that it isn't green and bolded like __includes or libraries, and you can use alias as an alias.
  4. Including a library in itself causes infinite recursion and the app freezes. This should be caught before it happens and a relevant error should be thrown.
  5. Included libraries are not private to the file in which they are included, which seems undesirable to me. For example, if I include library test in the Code tab, and I include library test2 in library test, I can now access library test2 from the Code tab.
  6. No error is thrown if you include the same library twice. Similarly, no error is thrown if you include a library once, and then include a different library that is aliased to the same name as the first library. This latter case is problematic, because both libraries are then included, and any command name conflicts become ambiguous. After messing around with it, I discovered that in that case, the version of the command from the first included library is used, and all other commands with the same name are silently ignored.

Let me know if I need to clarify anything I said.

@kgmt0
Copy link
Contributor Author

kgmt0 commented Apr 20, 2025

Thanks for testing!

  1. If you import a library and then just use its name without the colon and a command after it, the error message is "Nothing named xyz has been defined." I would expect it to be something along the lines of "xyz is a library, not a command."

Hmm. I didn't consider having a special error message for that because libraries are not (currently) a value, but I can see how users would find it helpful. Would love to hear what other people think as well.

  1. Imported libraries don't show up under the Included Files dropdown. This is probably up for debate but personally I would like it if they showed up there so I could easily open them.

I agree. I plan to implement this but haven't got to it yet.

  1. alias is used like a keyword as far as I can tell, but the compiler does not identify it as a keyword. This means that it isn't green and bolded like __includes or libraries, and you can use alias as an alias.

It's a bit different from other keywords because it only has a special meaning within the context of the libraries syntax. There's no problem if the user wants to name something "alias", or even use the word "alias" as an alias.

  1. Including a library in itself causes infinite recursion and the app freezes. This should be caught before it happens and a relevant error should be thrown.

Good catch! I'll fix that.

  1. Included libraries are not private to the file in which they are included, which seems undesirable to me. For example, if I include library test in the Code tab, and I include library test2 in library test, I can now access library test2 from the Code tab.

There's a (not yet implemented) define-libraries syntax that you'll be able to use to list exactly the symbols you want to export. Once that's implemented, I plan to make symbols private by default.

  1. No error is thrown if you include the same library twice. Similarly, no error is thrown if you include a library once, and then include a different library that is aliased to the same name as the first library. This latter case is problematic, because both libraries are then included, and any command name conflicts become ambiguous. After messing around with it, I discovered that in that case, the version of the command from the first included library is used, and all other commands with the same name are silently ignored.

Good point. I'll add some checks for that.

@kgmt0
Copy link
Contributor Author

kgmt0 commented Apr 20, 2025

Do you have documentation or a sample model to demonstrate the new syntax?

I sent you a link to the design document on Slack.

@kgmt0 kgmt0 force-pushed the libraries branch 3 times, most recently from 0cbc3b2 to 8c9e36f Compare April 20, 2025 07:30
@TheBizzle TheBizzle added this to the 8.0.0 milestone Apr 21, 2025
@kgmt0 kgmt0 force-pushed the libraries branch 4 times, most recently from 3be88da to 3b6c687 Compare April 24, 2025 06:52
@kgmt0 kgmt0 force-pushed the libraries branch 4 times, most recently from a6ef635 to aec791e Compare May 3, 2025 06:04
@brandesNW brandesNW deleted the branch NetLogo:main May 8, 2025 22:44
@brandesNW brandesNW closed this May 8, 2025
@LaCuneta LaCuneta reopened this May 9, 2025
@LaCuneta LaCuneta changed the base branch from hexy to main May 9, 2025 03:11
@kgmt0 kgmt0 force-pushed the libraries branch 4 times, most recently from 1918125 to 4b57666 Compare May 15, 2025 19:46
kgmt0 added 29 commits December 13, 2025 18:55
This doesn't actually do anything useful yet.
This makes it possible to different procedures with the same name in
different modules.
Also exclude globals, breeds, and breed variables from being imported.
Also set the module field of procedures imported with __includes to
None since they're supposed to be in the namespace of the model.
Add a field that lists different aliases of a procedure to different
variations of Procedure. This allows CompilerResult to generate the
correct procedure map from lists of procedures.
Change the message to "Module {0} has already been imported".
Also update the module loading mechanism to use package metadata file to
find module files.
This makes it possible to install packages through the extension
manager.
Previously, relative imports only tries to load module files relative to the
CWD. Fixes this so that it tries to load files relative to the
importing module instead.
For identifiers that contain colons, its tokens will be merged so that
they can be processed correctly by Namer.
Instead of prefixing the name with an underscore to avoid conflicts with
reserved keywords, surround it with backticks instead.
Use stripMargin so that multiline strings used in test cases can be
indented properly.
The new syntax looks something like this "import foo:bar as baz".
Remove this commit after testing is done.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants