>>>>> "Nicolas" == Nicolas Payette <
nicolas...@gmail.com> writes:
>> set my-home one-of intersections set my-workplace one-of
>> intersections other-than my-home
>>
>> Or do we already have this? That would be great (and embarrassing!)
Nicolas> set my-workplace one-of intersections with [ self != my-home ]
I also very much like James Steiner's suggestion of
set my-workplace [one-of other intersections] of my-home
If this is a solution that comes naturally to your mind, then you've
really learned how to think in NetLogo!
That doesn't cover the general set-difference case though, which I tend
to agree is a hole in the language. I don't have a real strong feeling
about it though since it isn't that hard to do:
to-report intersect [xs ys]
report xs with [member? ? ys]
end
The argument for adding it to the language would be strengthened by the
opportunity to provide an implementation that is asymptotically more
efficient that what you get with the above code. Does that opportunity
exist? Well, at present `member?` is O(n) on ordinary, non-breed
agentsets, so the above code is O(n * m), whereas if the code for the
proposed `intersect` primitive constructed a hash table from one of the
two sets, it could be O(n + m). But actually, it might not be necessary
to add the primitive to get the speedup. We could have `member?`
construct and cache the hash table, and then other sorts of code that
used `member?` would benefit too. Something to think about. It's
actually kind of crummy that agentset membership is O(n); generally
things called "sets" in programming languages are supposed to have
an O(1) or O(log n) membership test in order to earn the name.
--
Seth Tisue |
http://tisue.net