NetLogo / Tortoise

Compiler and runtime engine for NetLogo models that runs in JavaScript 🐢
https://netlogoweb.org
Other
56 stars 27 forks source link

unimplemented primitive: Warning, instead of Error #214

Open CIVITAS-John opened 4 years ago

CIVITAS-John commented 4 years ago

Hi all,

I wonder the rationale behind the decision that an unimplemented primitive in NetLogo Web shall report an error rather than a warning. When I created a model with behavior space support, I was forced to remove all file-related primitives before deploying it in NLW; that means I have to maintain two different versions, even when the file-related primitives will never trigger in NLW.

Hence, it resonates with my previous proposal of a unified API in the devel core meeting - that is, if I want to maintain a single version, I have to use Send-To at this moment. Yet, the send-to extension does not meet my intention to utilize file streaming - when I have to run 10,000s of experiments in behavior space, I cannot achieve what I have done in the following code:

Thanks!

Best, John Chen

LaCuneta commented 4 years ago

Hey John,

The original expectation was that if a primitive is used by a model, then the model will likely not run correctly without it. I'd argue this is a pretty good assumption. While your model works okay despite having the file primitives, most other models that use them will simply not work in NLW at all. This setup also comes from a time when many, many more primitives were not implemented in the NLW side.

We have, however, started adding errors for when primitives are used by a model rather than on load/compile. Things like import-pcolors give a specific error message that should help the user understand why it doesn't work, and if they don't actually use it they won't see the error. Those type of error messages might make sense to add for a few other primitives, like the file ones as you note. Others, like the HubNet primitives still seem to me to likely be "showstoppers" for trying to run a model.

We actually do "whitelist" some primitives like display that won't work correctly in NetLogo Web but cannot affect the behavior of a model, only how it looks. Those primitives do give a warning in the developer console when used. You're likely aware of this, just putting here for others reading this.

I hope that's helpful.

CIVITAS-John commented 4 years ago

Hi Jeremy,

Thanks for your long feedback - however, I wonder, in this special case (and I believe there are many cases in which the developer wants to use unsupported NLW primitives in a cross-platform model), the situation is that we can actually check whether this is a NetLogo Web model, similar to conditional compilation.

Or we should sit down here and think about a comprehensive way to do it. It shouldn't be hard. For example:

1) We allow every legal primitive in NetLogo to compile in NetLogo Web. 2) However, if we encounter something that is not supported by NLW, return warning(s) and display it somewhere, likely in the Command Center. 3) Moreover, if the code is executed and the unsupported primitive is met, throw a runtime error or warning.

I also wonder if it is possible to add an NLM? primitive to NL/NLW. (We should wait until Uri confirmed a formal name for it, just asking). Now that we have a dev intern working on javascript/coffeescript, it seems possible that I can have her do the job and submit a pull request.

Best, John Chen