Here is another article in my "romp" series, which intends to explain Perl 6 features drilling down from simple listings to the meaning behind everything. Here.

—John

Replies are listed 'Best First'.
Re: A Romp Around addn
by jethro (Monsignor) on Aug 17, 2008 at 11:54 UTC

    Thanks for this interesting and entertaining read (the same goes for the previous article about classes, only I got no useful comment on that)

    You emphasize the shortness of perl compared even to lisp. This reminds me of apl which made shortness a design principle and as a consequence could be called the first true write-only language. Sometimes I think Perl6 might have too much of apls density and adas feature creep. But then I need to remind myself that perl (5 and 6) is not one but many languages because of TIMTOWTDI. This is one big feature and there is a price to pay

      Did you read this one?

      Perl 6 doesn't have to be terse. Even moreso than in Perl 5, you can for example name the variables instead of using $_.

      —John

        So the APL library on cpan6 is not far away and all those old financial programs not written in COBOL will be moved over from ancient mainframes to perl. Hooray ;-)

        Terseness is not a problem in itself. No one likes to type 'System.out.println' instead of 'print' (one of the reasons I never got around programming in java).

        The problems begin when the redundancy is so low and the feature density so high that you can replace or add one single punctuation character or even a space and the statement is with high probability still syntactically correct and does something totally different.

        perl already has a reputation as a obfuscated language, this reputation might even get worse with perl6. I've gotten a lot better reading perl code since I've started posting here on perlmonks, but I still get the uneasy feeling occassionaly that the bug I identified in some users code might be valid syntax that I just forgot. Just a few days ago I saw that someone had typed =\ instead of =~ in his code. To my surprise the whole statement was still valid syntax but I couldn't say why at first. With the explosion of (syntactically) overloaded/reused punctuation characters in perl6 I fear I might get that surprise a lot more often

        Don't get me wrong, I like perl6 and the freedom of picking all the bits I like out of the language will make me a happy coder. And my fears are probably based on ignorance and an overdose of apocalypses read a long time ago. But my impression was that perl6 syntax has twice or three times as many constructs/elements as perl5 and instead of using words to make those constructs easily distinguishable, another layer of meaning is heaped upon some punctuation character.

        brackets have 4 uses in perl5 depending on context, caret three and colons two. In perl6 each has a lot more (if my impression is correct). Apart from the poor people who have to write the perl6 parser what about the humans who have to parse it?

Re: A Romp Around addn
by repellent (Priest) on Aug 17, 2008 at 18:34 UTC
    sub addn($n) { my $retsub = sub ($x) { $x + $n } return $retsub; }
    So, in Perl 6, by the time it gets into the first set of curlies { my ... }, $n is already a copy of the argument passed in to addn() and not simply an alias?

    No need to do the following?
    sub addn($n) { my $m = $n; my $retsub = sub ($x) { $x + $m } return $retsub; }
    I'm curious. Thanks.
      Thank you for finding that. $n is a read-only alias to the caller's value. I see your point: the original value might change, and that would affect the closure.

      However, you don't have to make a copy the way you show. Just change the parameter to pass-by-copy. I'll update the article.

      —John

Re: A Romp Around addn
by TimToady (Parson) on Aug 19, 2008 at 19:31 UTC
    Actually, you can't say $s += $^i for ^$n; because such implicit parameters are defined to scope to the nearest enclosing curlies, and the for modifier doesn't supply curlies.