Why/how etc does item list of list give column

When playing around with pixel manipulation in another post, I saw this in the manual

and I'm wondering if this item(list(list)) of list structure is just one of those shorcuts hard-coded into Snap! to select/swap columns in a 2 dimensional list or whether there is some logic that can be followed to explain it?

ok, so, here's something that might tell you what it does

so basically the pixels script

switches columns 1 and 2 of the pixels of the apple

1 Like

I know what it does :slight_smile:

Its the why that's the question :slight_smile:

@bh can you do this, I can't really explain how it works in a good way.

It uses hp blocks

The general principle is that when we introduced hyperblocks in 6.0 we also introduced the idea of matrices (and even higher-dimension arrays) as first class, and so we want to make manipulating columns as easy as manipulating rows. In particular, media computation on pictures (costumes) involves manipulating columns.

The specific details of how the ITEM block works come from a very hard-fought compromise between me and Jens. There is no solution that perfectly encompasses the need to be compatible with pre-6.0 ITEM, Jens's media computation, and my desire to emulate exactly the APL treatment of item selection. Really, we have arguments sometimes, but never before or (so far, knock on wood) since as long or heated as this one. We ended up working out a solution that we could both live with. You can look up the gory details in the Hyperblocks section of the manual.

Quick summary: If the first input to ITEM is a one-dimensional list (a list of numbers), it selects items of the second input; if that second input is a list of lists, then its items are the rows. If the first input is a two-dimensional list, then each of its items controls one dimension of the second input, so it's ITEM (LIST column-selector row-selector) OF matrix, where each of column-selector and row-selector is itself a list of numbers. For a 3-D array, it'd be
ITEM (LIST column-selector row-selector plane-selector) OF array.

As a shortcut, if one of the selector sublists is empty, it's equivalent to a list of all the numbers from one to the size in that dimension of the second input.

The key to the great compromise is ordering the selectors from minor dimension to major dimension, so it's column then row, not row then column. This is so that the selector list
(LIST (LIST 3 2 1)) isn't the same as just (LIST 3 2 1), giving instead a quick way to select columns.

1 Like

yeah, but how it works is not hyperblocks, it's a lot more complicated than that.

1 Like

That was the bit I hadn't realised before coming to pixel manipulation and my brain is now happy with that concept.


And then its happy with list(list()) being the syntax of of selecting columns :slight_smile:


[edit] And now, of course, I've found page 20 of The Manual which tells us all about using lists as item selectors :slight_smile: [/edit]