Archive for October, 2014

Flattening and such

October 13, 2014

A quick blog post to supplement discussion on IRC and (presumably) at the #APW hackathon.

I just did a couple of quick acks on the ABC codebase, and this is what I found:

Wynne:ABC colomon$ ack -Q .list
187:            for $bar.list {
202:                for $_.value.ast.list {

72:                for $match<key-def><global-accidental>.list -> $ga {

The first one here I totally understand why I have to use .list. The remaining two, though, are classic examples of where my intuition says “These should return a list I can loop on” but instead I get an item. I guarantee that both times I only added the .list after minutes of head-scratching about my code failing in mysterious ways.

Wynne:ABC colomon$ ack -Q .flat
147:        make (@chords, @texts).flat;

421:    is $match<header_field>{ .<header_field_name> }), "X T S M L K", "Got the right field names";
442:        is .<header_field>{ .<header_field_name> }), "X T S M L K", "Got the right field names";

Here the first one really is flattening, but I think is a prime example of why we need an explicit list concatenation operation.

The remaining two … I’m not sure if I really meant .flat or .list there. Let me go look at the code…

Updated: Yes, .list gives me the same results on those last two. So in practice they are probably another example where I just tacked something randomish on to get things to behave the way I thought they should have by default.

Update to the update: Actually, for those last two, it works fine without .list or .flat. So that call was necessary at some point (or I wouldn’t have added it) but is no longer.

Another update: Okay, I tried removing the second two .lists from the first batch. line 202 can be removed without breaking any tests. line 72 breaks loads of tests if the .list is removed.

Also, it appears my code is using @( $match ) and similar constructions much more often than it is using .list or .flat. Again the standard usage is somewhere I would have expected it to not be needed.