Apply block strangness

@qw23

Got a strange one
Was trying to use your apply block to do other stuff than summing but just couldn't get it to work

In desperation, I recreated it and my version works!

But AFAICT - they should behave identically

Any idea as to what is going on???

untitled script pic (60)

untitled script pic (61)


[edit] I've just spotted the difference


Yours is using input list - mine is using with inputs
Which explains why it works with sum block as it's summing all the items of the input list but doesn't work with reporters like length because that only gets supplied with 1st item of the list

:slight_smile: #MysterySolved
[edit2] But now simply summing doesn't work so it's not a solution - just an explanation :slight_smile:
[edit3] Well it does work if I use #1 :slight_smile:
groupAndSum script pic (14)

Yeah, the distinction between an ordinary list and what’s called an input list in Snap! is a real stinker. I, for one, mix ‘em up more often than I like.

My version of apply assumes the function is defined for an entire list, not for each individual item. So to get a new set of a-lists each composed of a key and the average of the associated values, one would have to call a function reporting the average of a list of values - currently not a Snap! primitive, AFAIK:

Still, I’m a bit confused myself as to whether using with inputs or input list is the way to go forward.

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