Using negative indicies to select items from end of a list

I'm seeing stuff going on in the engine room that looks like the item x of [data] is being altered to handle negative numbers to make it easy to count from the end of a list without having to find out its length

Now I've been wanting such a facility for a long time and have my own reporter to do this
Its a combo of red and green to show that it works on both text and lists

uniqueCompressionImage script pic (1)
Now my attitude is that since Snap! uses 1-based indexing e.,g item 1 of[a,b,c,d,e] is a, then item (-1) of [a.b.c.d.e] should be e (and not d)

i.e 1 gives first item, -1 should give last item

What do others think?

Or do you think 0 should select last item and -1 give 2nd last item

apologies that im missing the entire point of this but, what do you mean by

where is this metephorical engine room?

edit: i really should have checked the patch notes huh

The point up for discussion is what item in a list [a,b,c,d,e] should item(-1) return

The rest is social banter and irrelevant to the point :slight_smile:

i ment i apoligse for focusing on something that isnt the main point here

That's what people do on forums all the time :slight_smile:

is this version even out? i cant seem to get it or even the new libraries to load/show

It not necessary to load it in to have an opinion on the indexing question :slight_smile:

i still would like to test it out

yeah, we're playing with a bunch of ideas, but I don't think that experiment will make it into production. Probably the best solution would be a little library with a (wrapped item _ of _) reporter and another (slice _ from _ to _) one, whereas both would use negative indices as offsets from the end, and both can easily be built in Snap! itself.

Those ideas sound good :slight_smile:

No, not another little library! Put those blocks in List Utilities where people will actually be able to find them.

Where are the patch notes?


I was afraid of that... (my school blocks github.)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.