Schwartzian transform

Alex Balhatchet kaoru at slackwise.net
Wed Aug 13 11:12:31 BST 2014


D'oh. Thanks for schooling me on 'map EXPRESSION' gents. I do vaguely
remember seeing that before, but I never use it so I completely forgot
about it :-)

- Alex

On 13 August 2014 11:03, Abigail <abigail at abigail.be> wrote:
> On Wed, Aug 13, 2014 at 10:50:39AM +0100, Alex Balhatchet wrote:
>> Hi Dermot,
>>
>> You have a few problems with your code:
>>
>> 1. First argument to map is a block
>
> First argument of map is either a block, or an expression.
>
>> You should be wrapping your code block to map with curly braces.
>>
>> eg. map { [ $_, $ref->{$_}{position} ] }
>
> No, not required. His code is fine.
>
>> 2. No need to use $ref in your second (chronologically by execution,
>> first by line number) map
>>
>> The Schwartzian Transform puts the original value into the first
>> element of the array reference, so to map back you just take $_->[0].
>
> But then you would end up with a list of keys, his code ends up with a
> list of records. Those are different things.
>
>> 3. Some mis-placed commas
>>
>> When chaining maps and sorts you don't need commas, because there
>> should be no comma separating your block from the next argument to map
>> (this is related to my first point.)
>
> This goes back to point one. You don't know map. The commas are actually
> required here, as he's using the "map EXPRESSION" syntax.
>
>
> His code is actually fine, and runs without any modifications.
>
>
>
> Abigail


More information about the london.pm mailing list