asfallows
asfallows

Reputation: 6108

Overloading a function in NetLogo

I am developing a simulation in NetLogo that will ultimately have multiple permutations. In the end, I'll have Sim1.nlogo, Sim2.nlogo, Sim3.nlogo, et cetera all including libsim.nls.

What I'd like to know is, if I have a function in libsim.nls that is identical in all but one of my models, can I overload it in the model that differs, or will I have to duplicate the code manually in each permutation?

Upvotes: 2

Views: 143

Answers (1)

Seth Tisue
Seth Tisue

Reputation: 30453

The exact thing you're asking for isn't possible. But you don't need to duplicate code in all of the models, either.

I'd suggest the following approach. In libsim.nls, give the standard implementation a standard name like foo-standard. Then in Sim1.nlogo and Sim2.nlogo you can have the one-liner to foo foo-standard end, and in Sim3.nlogo you can have to foo ... end with a different body, that doesn't call the "standard" implementation.

Upvotes: 3

Related Questions