On 08/13/2014 05:33 AM, Dermot wrote:
Hi
Sorry for the OT post :)
I am trying to transform the hash reference below so that the value of
position is ordered from 1..4. The sorting works but I can't seem to modify
the value of {position} inline. To achieve what I want I have to look
through the
On Wed, Aug 13, 2014 at 01:45:24PM +0100, Dermot wrote:
> On 13 August 2014 13:24, Abigail wrote:
>
> > On Wed, Aug 13, 2014 at 09:45:59PM +1000, Damian Conway wrote:
> > > Mark and Aaron are ntirely correct that the ST is not required for your
> > example,
> > > but if your actual application us
On 13 August 2014 13:24, Abigail wrote:
> On Wed, Aug 13, 2014 at 09:45:59PM +1000, Damian Conway wrote:
> > Mark and Aaron are ntirely correct that the ST is not required for your
> example,
> > but if your actual application uses a significantly larger dataset than
> just
> > four hash entries,
That's awful. He was a great bloke, and I enjoyed our chats on #dancer.
On 13 Aug 2014, at 10:23, David Precious wrote:
>
> Hi all,
>
> (Posted this to dancer-users first; it was suggested that it be posted
> to london-pm too as several mongers had met/knew James.)
>
>
> Sadly, my friend and
On Wed, Aug 13, 2014 at 09:45:59PM +1000, Damian Conway wrote:
> Mark and Aaron are ntirely correct that the ST is not required for your
> example,
> but if your actual application uses a significantly larger dataset than just
> four hash entries, then the ST may still be preferable...as array loo
> In the absence of such benchmarking (and also in the absence of any
> indication of a performance issue) I think the approach of directly
> sorting the hash refs wins merely by virtue of being so much simpler.
Agreed.
Although, I took the the use of the ST in the original code
as precisely that
On 13 August 2014 12:17, Aaron Crane wrote:
> Dermot wrote:
> > my $count = 1;
> > my @sorted =
> > map { $ref->{ $_->[0] }->{position} = $count++; $ref->{ $_->[0] } }
> > sort { $a->[1] <=> $b->[1] }
> > map [ $_, $ref->{$_}->{position} ],
> > keys %{ $ref };
>
> It's not clear
Damian Conway wrote:
> Mark and Aaron are ntirely correct that the ST is not required for your
> example,
> but if your actual application uses a significantly larger dataset than just
> four hash entries, then the ST may still be preferable...as array lookups
> are around twice as fast as hash l
On Wed, Aug 13, 2014 at 01:28:57PM +0200, Abigail wrote:
> [1] Well, it may depend on what definition of lazy you mean. Obviously,
> you can't "lazyly" [3] sort an infinite list, as you need to process
> all elements at least once to be able to return a first element.
> But using, for i
Abigail asked:
> [3] Is ["lazyly"] a real word?
Very nearly. "Lazily" is the generally accepted spelling.
Though I guess one could argue that "lazyly" is "lazily" spelt lazily,
and hence is even more correct. ;-)
Damian
Mark and Aaron are ntirely correct that the ST is not required for your example,
but if your actual application uses a significantly larger dataset than just
four hash entries, then the ST may still be preferable...as array lookups
are around twice as fast as hash lookups. That might be a significa
On Wed, Aug 13, 2014 at 01:13:42PM +0200, Mark Overmeer wrote:
>
> Sort is not lazy (cannot be lazy), so this suffices:
Perls current implementation of sort isn't lazy, but I see no reason
why sort cannot be lazy [1] [2]. If only the first 10 elements of the output
of sort are needed, there's no
Dermot wrote:
> my $count = 1;
> my @sorted =
> map { $ref->{ $_->[0] }->{position} = $count++; $ref->{ $_->[0] } }
> sort { $a->[1] <=> $b->[1] }
> map [ $_, $ref->{$_}->{position} ],
> keys %{ $ref };
It's not clear to me that the Schwartzian Transform adds anything to
this code
Considering you wanted to golf, here's my entry [0]:
map$$ref{s/..//r}{position}=++$::x,sort+map"$$ref{$_}{position},$_",keys%$ref
Now, this will break if the value "position" field of the original structure
is outside of the range 0..9 [1], but that isn't the case in your example.
It makes
* Dermot (paik...@gmail.com) [140813 11:08]:
> >
> >
> > # Warning: map in void context used for side-effect of setting
> > {position}...
> > # (I feel so dirty! ;-)
> > my $count = 1;
> > map { $_->[1]{position} = $count++ }
> > sort { $a->[0] <=> $b->[0] }
> > map { [$_-
>
>
> # Warning: map in void context used for side-effect of setting
> {position}...
> # (I feel so dirty! ;-)
> my $count = 1;
> map { $_->[1]{position} = $count++ }
> sort { $a->[0] <=> $b->[0] }
> map { [$_->{position}, $_] }
> values %{$ref};
>
>
>
That is filt
If you only want to modify the original hash, you just need this:
# Warning: map in void context used for side-effect of setting {position}...
# (I feel so dirty! ;-)
my $count = 1;
map { $_->[1]{position} = $count++ }
sort { $a->[0] <=> $b->[0] }
map { [$_->{position}, $
Olé
Thank you Adrian. Your golf is good.
my $count = 1;
my @sorted =
map { $ref->{ $_->[0] }->{position} = $count++; $ref->{ $_->[0] } }
sort { $a->[1] <=> $b->[1] }
map [ $_, $ref->{$_}->{position} ],
keys %{ $ref };
I sometimes question the legibility of such code but as an ex
On 13 Aug 2014, at 11:12, Alex Balhatchet wrote:
> 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 :-)
It’s amazing what you can fit into an expression (especially with parens), and
the exp
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 wrote:
> On Wed, Aug 13, 2014 at 10:5
On 13 August 2014 11:11, Adrian Lai wrote:
> You possibly want:
>
> map { $ref->{ $_->[0] }->{position} => $count++; $ref->{$_->[0]} }
Bad copy/paste/editing, I meant:
map { $ref->{ $_->[0] }->{position} = $count++; $ref->{$_->[0]} }
Adrian.
>I assume that Dermot was using the second version that doesn't need the
braces and does need the comma.
I am often caught out between when to use the comma and not but it's "()"
and comma or braces and no comma, I believe.
Abigal: I wanted to avoid doing the foreach loop at the end. I hoped I
co
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 wrote:
> On Wed, Aug 13, 2014 at 10:50:39AM +0100, Alex Balhatchet wrote:
>> Hi Dermot,
>>
>> You have
On 13 August 2014 10:33, Dermot wrote:
> #map { $ref->{ $_->[0] }->{position} => $count++ }
You probably want = $count++, rather than =>.
You possibly want:
map { $ref->{ $_->[0] }->{position} => $count++; $ref->{$_->[0]} }
Adrian.
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
Quoting Alex Balhatchet :
Hi Dermot,
You have a few problems with your code:
1. First argument to map is a block
[ snip]
3. Some mis-placed commas
[ snip ]
Actually, map has two forms.
map BLOCK LIST
map EXPR, LIST
I assume that Dermot was using the second version that doesn't nee
* Dermot (paik...@gmail.com) [140813 09:37]:
> I am trying to transform the hash reference below so that the value of
> position is ordered from 1..4.
I think I understand what you mean.
> my @sorted =
> map $ref->{$_->[0]},
> #map { $ref->{ $_->[0] }->{position} => $count++ }
should hav
Hi Dermot,
You have a few problems with your code:
1. First argument to map is a block
You should be wrapping your code block to map with curly braces.
eg. map { [ $_, $ref->{$_}{position} ] }
2. No need to use $ref in your second (chronologically by execution,
first by line number) map
The S
On Wed, Aug 13, 2014 at 10:33:50AM +0100, Dermot wrote:
> Hi
>
> Sorry for the OT post :)
>
> I am trying to transform the hash reference below so that the value of
> position is ordered from 1..4. The sorting works but I can't seem to modify
> the value of {position} inline. To achieve what I wa
Hi
Sorry for the OT post :)
I am trying to transform the hash reference below so that the value of
position is ordered from 1..4. The sorting works but I can't seem to modify
the value of {position} inline. To achieve what I want I have to look
through the @sorted array. I'd like to golf this if
Hi all,
(Posted this to dancer-users first; it was suggested that it be posted
to london-pm too as several mongers had met/knew James.)
Sadly, my friend and colleague James Aitken (LoonyPandora/JAITKEN), who
contributed to Dancer and wrote several Dancer plugins, died
unexpectedly last week.
H
31 matches
Mail list logo