Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^5: What's wrong with Perl 6?

by blazar (Canon)
on May 14, 2007 at 09:04 UTC ( [id://615248]=note: print w/replies, xml ) Need Help??


in reply to Re^4: What's wrong with Perl 6?
in thread What's wrong with Perl 6?

It's funny that you compare it to the ugly new Mustangs. You're right that it looks Perlish, but looking at this example from this article, my first guess would probably be Ruby or maybe Java

That is an example that exhibits explicit features related to Perl 6's OO system. The code is not all that different from Perl 5 (roughly) equivalent one except for some syntactical bits, and the fact that in the latter you should build yourself some stuff that in this case is instead part of the language.

For "normal" usage, whatever that is, I can't see e.g.

.say for =$fh;

as being significantly less perlish than

print while <$fh>; # assuming $\="\n"

I would rather say: differently so.

OTOH I'm glad to be able to do e.g.:

pugs> sub postfix:<!> (Int $n) { [*] 1..$n } undef pugs> say $_! for ^6 1 1 2 6 24 120 undef

(As you can see this has the advantage of being able to be already run under pugs - it is also quite about the only thing I can do! :-)

Even in the example code you presented, though, there are many bits that IMNSHO are very perlish, although also very different from current Perl look and feel:

  • Perl's typical way to do things implicitly on the $_ pronoun, in this case by means of "unary" dot;
  • Perl's dwimmery fashion with 0 < $rank < 10 which is more clear and concise than the full expression comprising a logical operator.

Also see the following portion of a recent clpmisc thread (link @ GG):

From: Abigail <abigail@abigail.be> Subject: Re: I find the perl syntax easier than python Message-ID: <slrnf3kdgg.hl5.abigail@alexandra.abigail.be> Date: 03 May 2007 19:21:12 GMT Michele Dondi (bik.mido@tiscalinet.it) wrote on MMMMCMXCII September MCMXCIII in <URL:news:7vqh339jps8hbki5biisah7iaf0nlctdcn@4ax.com>: \\ \\ Since I mentioned Perl 6 above, in it eventually we will have more \\ convenient ways and less ambiguity in passing parameters. We will \\ still be able to use @_ & C. but who does really need them when yo +u \\ can do \\ \\ sub addprint ($n,$m) { say $n+$m } # ? And this is an advantage? Limiting yourself to two arguments? In Perl5, you aren't tempted to use named variables, so you get your arguments in an array. And given an array, it's natural to allow a variable number of arguments: sub addprint {my $sum = 0; $sum += $_ for @_; print $sum, "\n"} Abigail -- $_ = "\nrekcaH lreP rehtona tsuJ"; my $chop; $chop = sub {print chop; +$chop}; $chop -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ( +) -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ( +) -> ()
From: "David Formosa (aka ? the Platypus)" <dformosa@usyd.edu.au> Subject: Re: I find the perl syntax easier than python Message-ID: <slrnf3kk20.o5h.dformosa@localhost.localdomain> Date: Thu, 03 May 2007 21:02:45 GMT On 03 May 2007 19:21:12 GMT, Abigail <abigail@abigail.be> wrote: > In Perl5, you aren't tempted to use named variables, so you get > your arguments in an array. And given an array, it's natural to > allow a variable number of arguments: > > > sub addprint {my $sum = 0; $sum += $_ for @_; print $sum, "\n"} So you do something like this sub addprint (*@num) { say [+] @num };
From: Abigail <abigail@abigail.be> Subject: Re: I find the perl syntax easier than python Message-ID: <slrnf3kk1c.hl5.abigail@alexandra.abigail.be> Date: 03 May 2007 21:12:37 GMT David Formosa (aka ? the Platypus) (dformosa@usyd.edu.au) wrote on MMMMCMXCIII September MCMXCIII in <URL:news:slrnf3kk20.o5h.dformosa@lo +calhost.localdomain>: ^^ On 03 May 2007 19:21:12 GMT, Abigail <abigail@abigail.be> wrote: ^^ ^^ > In Perl5, you aren't tempted to use named variables, so you get ^^ > your arguments in an array. And given an array, it's natural to ^^ > allow a variable number of arguments: ^^ > ^^ > ^^ > sub addprint {my $sum = 0; $sum += $_ for @_; print $sum, "\n +"} ^^ ^^ So you do something like this ^^ ^^ sub addprint (*@num) { say [+] @num }; Yeah, but that's only on the second try. ;-) Abigail -- #!/opt/perl/bin/perl -w $\ = $"; $; = $$; END {$: and print $:} $SIG {TERM} = sub {$ := $_}; k +ill 15 => fork and ($; == getppid and exit or wait) foreach qw /Just another Per +l Hacker/
From: "David Formosa (aka ? the Platypus)" <dformosa@usyd.edu.au> Subject: Re: I find the perl syntax easier than python Message-ID: <slrnf3mb1l.o5h.dformosa@localhost.localdomain> Date: Fri, 04 May 2007 12:41:14 GMT On 03 May 2007 21:12:37 GMT, Abigail <abigail@abigail.be> wrote: > David Formosa (aka ? the Platypus) (dformosa@usyd.edu.au) wrote on > MMMMCMXCIII September MCMXCIII in <URL:news:slrnf3kk20.o5h.dformosa@ +localhost.localdomain>: > ^^ On 03 May 2007 19:21:12 GMT, Abigail <abigail@abigail.be> wrote: [...] > ^^ > sub addprint {my $sum = 0; $sum += $_ for @_; print $sum, " +\n"} > ^^ > ^^ So you do something like this > ^^ > ^^ sub addprint (*@num) { say [+] @num }; > > Yeah, but that's only on the second try. ;-) But mine is more elegant.
From: Michele Dondi <bik.mido@tiscalinet.it> Subject: Re: I find the perl syntax easier than python Message-ID: <mtlk33ptfdohop2qcqipp7pvas9r1a1r5q@4ax.com> Date: Thu, 03 May 2007 23:45:03 +0200 On Thu, 03 May 2007 21:02:45 GMT, "David Formosa (aka ? the Platypus)" <dformosa@usyd.edu.au> wrote: >So you do something like this > >sub addprint (*@num) { say [+] @num }; D'Oh, you beat me. But in my example I showed our friend Abigail that if you really want you still have @_. Michele -- {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB=' .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_, 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
From: Michele Dondi <bik.mido@tiscalinet.it> Subject: Re: I find the perl syntax easier than python Message-ID: <g7lk33h51ljljhsi7p83g7qhfmj120n6de@4ax.com> Date: Thu, 03 May 2007 23:41:26 +0200 On 03 May 2007 19:21:12 GMT, Abigail <abigail@abigail.be> wrote: >\\ sub addprint ($n,$m) { say $n+$m } # ? > >And this is an advantage? Limiting yourself to two arguments? Well, you know perfectly well that this is an *artificial* example to mimic the OP's one. But yes, it's there for those cases in which I *do* want to limit myself to two arguments, and perhaps type check them. >In Perl5, you aren't tempted to use named variables, so you get >your arguments in an array. And given an array, it's natural to I can't believe you're implicitly assuming that those guys aren't thinking of letting you do that in Perl 6 too, and more. >allow a variable number of arguments: > > sub addprint {my $sum = 0; $sum += $_ for @_; print $sum, "\n"} Funny, in Perl 6 that could be sub addprint {say [+] @_} Michele -- {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB=' .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_, 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,

Replies are listed 'Best First'.
Re^6: What's wrong with Perl 6?
by Cap'n Steve (Friar) on May 14, 2007 at 23:33 UTC
    Well, I guess we have different definitions of "Perlish". I was thinking "similar to past versions of Perl" and you seem to be thinking "conforms to the Perl philosophy". With your example of .say for =$fh;, once again the only thing that I would call Perlish about that is the dollar sign, and if you changed the variable name I'd have no clue what it does.
      Well, I guess we have different definitions of "Perlish". I was thinking "similar to past versions of Perl" and you seem to be thinking "conforms to the Perl philosophy".

      ++ because even if I disagree, you raised some important points. Indeed I was replying much along the lines of what TimToady explained earlier in this thread. Not because I took that as a revelation (although I find it to be so instructive and pleasantly written as usual) but because I'm already much thinking/feeling that way.

      With your example of .say for =$fh;, once again the only thing that I would call Perlish about that is the dollar sign, and if you changed the variable name I'd have no clue what it does.

      Well, then the semicolon appears to be statement delimiter too! ;-) But seriously, there's at least another very perlish thingy: the for statement modifier. This is just the same as Perl 5's. The real difference being that although both in 5 and 6 TMTOWTDI it's also true that in both there's often a preferred WTDI for most common situations, and in Perl 5 we often recommend to use a while loop to iterate over a filehandle unless there's a good reason to slurp the whole file in at a time. This has been occasionally source of confusion. But Perl 6 goes one step further making the whole thing more consistent thanks to its lazy evaluation model, so that for is suitable to iterate over any iterator. Said this, if you compare <$fh> and =$fh, you will notice that the former you're familiar with. The second, not. But if you knew neither, they would be equally strange, perhaps but the fact that the = sign is also used for more familiar things, like assignment; OTOH as $Larry says, the unary one also visually conveys the idea of lines from a file and thus does make sense. Last, say() is something that semantically has been missing in Perl for a long time, but then its name strongly suggests what it does. I'm not commenting on the dot and in particular the unary one, which is... well not much pre-6'ish, but is indeed very perlish in the sense above.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-25 14:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found