Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Indispensible language features

by FoxtrotUniform (Prior)
on Jul 07, 2004 at 23:57 UTC ( [id://372622]=note: print w/replies, xml ) Need Help??


in reply to Re: Indispensible language features
in thread Indispensible language features

I find it amazing that you find five characters (the space is optional) for lambdas too long -- heck, the proper name of the feature is longer then that.

I've given this a bit of thought: it's not so much the sub {...} part that I find verbose as the fact that I can't bind variables in a convenient way: I either have to use up keystrokes with a my ($x,$y,$z) = @_; at the front of the lambda, or constantly index @_ (which looks awful).

For instance, in Haskell the "zip" function (take a pair of lists and return a list of pairs) is defined as:

zip = zipWith (\x y -> (x,y))
(What's important here is the lambda.) In Perl, assuming an equivalent zipWith, you'd have to say:
zipWith {[$_[0], $_[1]]} @foo, @bar; # or: zipWith {($a,$b)=@_;[$a,$b]} @foo, @bar; # or: zipWith {[unshift,unshift]} @foo, @bar;
none of which looks as pretty. That's more a matter of opinion, of course.

--
F o x t r o t U n i f o r m
Found a typo in this node? /msg me
% man 3 strfry

Replies are listed 'Best First'.
Re^3: Indispensible language features
by TimToady (Parson) on Jul 08, 2004 at 20:40 UTC
    I agree, none of those are pretty. In Perl 6 you can also use either of:
    zipWith {[$^a, $^b]} @foo, @bar;
    or
    zipWith -> $a, $b {[$a,$b]} @foo, @bar;
    But then, your entire OP reads a bit like an ad for Perl 6... :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://372622]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-03-29 01:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found