Top 10 perl books

Abigail abigail at abigail.be
Thu Apr 24 10:27:02 BST 2008


On Thu, Apr 24, 2008 at 04:51:55AM +0100, Greg McCarroll wrote:
> On Wed, Apr 23, 2008 at 06:39:28PM +0100, Frank v Waveren wrote:
> >
> > syntactic sugar
> > 
> 
> Maybe I'm just getting old, but the more I think about syntactic sugar
> the more I appreciate it.
> 
> Map clearly tells me that you want to move from one list of things to
> a transformed list[1], grep tells me you want to reduce a list of things
> based on some logic.
> 
> The same with
> 
>     for (@things) {
> 
> vs.
> 
>     foreach my $thing (@things) {
> 
> The first sets me up to look out for $_. Lastly
> 
>     sub foo {
> 	my $self = shift;
> 	my ($whatever,...) = @_;
> 
> is instantly recognisable as a method.
> 
> My feeling is that syntactic sugar helps the equivalent of muscle
> memory for the brain, you just dont have to actually consciously think
> as much to figure out whats going on.
> 
> If I was language designer I think this would be the axe I'd want to
> grind - a simple basic language with an evolving set of macros on top
> to allow people to figure out how best to explain what low level
> patterns are going on.


This is what LISP is, isn't?

> [1] There is a bit of me that would further like to see this
>     constrained to the output having the same number of
>     elemements & structure and an additional bit of syntactic sugar
>     added for when this is not the case.


You mean something like:

    sub map_one2one (&@) {map {scalar &{$_ [0]}} @_ [1 .. $#_]}


I like the ability of map to return a list of a different length
than its input.

    %hash = map {($_ => 1)} @array;

is something I do quite commonly.


Abigail
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://london.pm.org/pipermail/london.pm/attachments/20080424/080b91b4/attachment.pgp


More information about the london.pm mailing list