Schwartzian transform

Kieren Diment diment at gmail.com
Wed Aug 13 11:14:44 BST 2014


And the first rule of the Schwartzian transform it to put a comment at the top of the code paragraph:

# Warning, schwartzian transform ahead.   If you need help with maintenance hit whoever git blame says’ fault it is.


On 13 Aug 2014, at 8:03 pm, 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