Use of Map that I don't understand


I created those blocks :

untitled script pic(86)

And it seems to work properly :

But I do not understand this :
untitled script pic(89)

where Id_( ) is :

untitled script pic(92)

Does someone can explain this, please ?

Can you post a project link with those blocks in please?

Sure. In the first case all the values in each row are different.

But in the second case, each row has three zeros, so when you do
and A is zero, all three zeros are removed at once.

One solution would be for SHUFFLE to start by making a list in which each item is a two-item list of the original item and its index. Then the values will forcement be unique (how do you say that in English?), and your KEEP will work, and then you do the inverse function to remove the index from the items.

Edit: "necessarily"!

Thank you @bh !

Yes, I noticed when I created my shuffle block that it would work only on lists that not contain duplicates, then afterwards, I forgot it !

So now, the only thing I do that works is :

But I have two big problems :

  • the first is that it shakes only the lines of the input
  • the second is that I don't succeed in transforming it into function. Whatever
    I do, the reporter doesn't fit.

For example, I tried to do this :

which reports :
untitled script pic(95)

The problem is that data_2 has its dimension that changes right after the first recursive call of the function.

Finally, I created this block that works :

Now I must shake the values upon the whole matrix...

And here it is :

Do you have a solution without using the APL Library ?

Yes, the LENGTH OF block includes a DIMENSIONS (same as SHAPE in APL) option and a FLATTEN option. And there's a primitive RESHAPE.

Instead of remaking the value-index pairing each time, I'd use a helper procedure:

where shuffle-helper is your original imperfect shuffle procedure.

A simple, naive implementation does not work for your problem?

untitled script pic - 2022-04-13T004457.439

A list build this way seems to have proper randomness (i've checked this, once, for 100k samples of 50 elements list)

Thank you @dardoro.
Yes, it must work properly. But, according to this help notice :

I prefer to use reporter blocks whenever possible, to manipulate linked lists instead of dynamic arrays.
It is more efficient specially when you have a lot of data to manipulate.

Fantastic ! Thank you @bh.
Moreover, it allows me to divide by 10 the time to shake a random matrix of size 100.

That is why Snap*!* is fantastic. It's full of hidden little nooks and crannies.
I didn't notice that LENGHT OF could be replaced by another object...

It depends on system performance but on i7 8th gen
untitled script pic - 2022-04-13T215913.648

and for 10^4 elements
untitled script pic - 2022-04-13T215951.779

Project Username=dardoro&ProjectName=shuffle

BTW: "for each..." yields for every iteration, so it must be "warped"

Yes, of course. Thank you for testing it.