[m-users.] Cartesian product of two sets of things.

Sean Charles (emacstheviking) objitsu at gmail.com
Tue Oct 10 17:37:11 AEDT 2023


Hi Julien,

In my original post there is this line of code:

 % set_hit(), Target is not mutable here...have another think!

I initially thought that I would indeed set the hit flags on the targets at the time the collision detection code said something was hit. I do indeed already have an earlier version that does this, obviating the needs for the sets at all, but for some reason I decided to do some experiments to see where it would lead.

Since my question, I have now seen a nice cartesian solution I didn't know about, and decided to reinstate my initial, what I thought could have been fancier solution, and just call the set_hit() function on the object(s)...this of course means that the output from the collision detector is just updated lists of input objects, meaning, yes, I don't need any of the ID sets blah blah blah.

Sometimes you just have to tinker to see what the options are and what benefits they may/may not have.

Thanks all,
Me.


> On 10 Oct 2023, at 07:09, Julien Fischer <jfischer at opturion.com> wrote:
> 
> 
> On Mon, 9 Oct 2023, Sean Charles (emacstheviking) wrote:
> 
>> The output is two lists, the object IDs of those things involved in collisions.
>> My question then is, given the two loops are basically generating a
>> cartesian product, is there a module function somewhere that would do
>> that for me, generate a single list of all pairs? Then I could
>> list.chunk and maybe produce a cleaner bit of code. I am currently
>> also considering on uncommenting out the set_hit() typeclass predicate
>> so that I can modify the objects in place, so instead of returning two
>> sets of objects ID,s I'd be returning a new set of objects with their
>> respective hit flags set.
> 
> My questions are: what do you do with those object ids once you have
> them? And could you do whatever that is inside the loop that generates
> the Cartesian product without building up a list or set containing the
> product?
> 
> Julien.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20231010/5ff8531e/attachment-0001.html>


More information about the users mailing list