in reply to Re^4: Perl6 syntax being too much complex? How we will teach and read that?!
in thread Perl6 syntax being too much complex? How we will teach and read that?!

I think we are saying much the same thing, but quibbling over terms :) I'd only note that there is a difference between "useful" and "usability".

I like the "raw parse trees" description of LISP. I'd never really thought of it that way, but it is a very accurate description from my less than comprehensive knowledge of the language. I assume that there is some mechanism for code re-use in LISP? Even if it is only something like include files? I also have no idea how you would read/write a file in LISP. I keep meaning to get around to installing a build of Scheme and playing.

P6 is definitely doing some things to orthoganise the language--consistant use of $, @, % comes to mind--but there are other areas where calls for orthoganality have been rejected. The most obvious example I can think of is length. I don't think that we are likely to see

my $sizeOfArray = @array.length;
or
my $sizeOfArray = length @array;
nor
my $lenOfString = scalar @$scalar;
(though I personally still hanker for my $substring = $scalar[ 3 .. 7 ];).

So, whilst P6 is regularising the language in many places, it's being done not for sake of orthoganality itself, but to simply the use of the language. If it also makes it more elegant, thats great, but I don't think that is the primary drive for change.

Let me add, I think that Perl 5 can be elegant. Some of Abigail's recursive solutions are extremely elegant. Likewise some of your code. But as you've noted about some of my P5 in the past, it's also possible to produce stuff which is "Yuck!":)

As for C++. I've fairly recently discovered a language that I think achieves most of what C++ set out to achieve (except backwards compatibility), but that does it with much less complexity. It's still evolving, and I haven't had opportunity to make a great deal of use of it in larger programs yet, but the simplicity of its objects, the automatic memory management, built-in associative arrays endear me to it strongly.

The fact that I can still get down and dirty with the machine as with C, but have a few more HLL features to simplify things, plus the compiled-to-native performance make it really interesting to me.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail

Replies are listed 'Best First'.
Re: Re: Re^4: Perl6 syntax being too much complex? How we will teach and read that?!
by TimToady (Parson) on Mar 25, 2004 at 03:26 UTC
    In fact, you're not even going to see
    my $sizeofstring = length($string);
    That's because "length" has been deemed to be an insufficiently specified concept, because it doesn't specify the units. Instead, if you want the length of something in characters you use
    my $sizeinchars = chars($string);
    and if you want the size in elements, you use
    my $sizeinelems = elems(@array);
    This is more orthogonal in some ways, insofar as you can now ask for the size in chars of an array, and it will add up all the lengths of the strings in it for you:
    my $sizeinchars = chars(@array);
    And if you ask for the number of elems of a scalar, it knows to dereference it:
    my $ref = [1,2,3]; my $sizeinelems = elems($ref);
    These are, in fact, just generic object methods:
    @array.elems $string.chars @array.chars $ref.elems
    And the functional forms are just method calls in disguise.

    So maybe length() is a bad example now. Sorry. :-)

    By the way, you can also use %hash.elems, which returns the number of pairs in the hash. I don't think %hash.chars is terribly useful, but it will tell you how many characters total there are in both keys and values.

    Actually, the meaning of .chars varies depending on your current level of Unicode support. To be more specific, there's also:

    $string.bytes $string.codepoints $string.graphemes $string.letters
    ...none of which should be confused with:
    $string.columns
    or its evil twin:
    $string.pixels

      Better & better.

      Presumably my elems = $nonrefscalar.elems; is just an error?

      Do you need the parens for the functional form or can you do my $noffchars = chars $scalar:;


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail
        Well, everything's an object underneath if you scratch it, so whether $nonrefscalar.elems returns an error probably depends on how $nonrefscalar is "tied" as a container object, to use the Perl 5 term. In general it's probably an error for the default implementation of scalars. Possibly it should return an undef containing an unthrown exception. Either that, or it should always return 1. :-)

        The parens are not necessary for an indirect object, which your colon forces it to be. Chances are it'll even work without the colon, because the syntactic function of the colon is to separate the indirect invocant from its arguments, and if there are no arguments, it's not ambiguous. It's only with arguments that the colon becomes obligatory.

        Basically, the dispatch rules are defined such that, for argumentless methods, it doesn't matter whether you call them as methods or subroutines--you end up at the same place. So you don't have to care whether

        close $handle;
        is defined as a global, multi-dispatched subroutine or as a normal method on filehandles.
Re^6: Perl6 syntax being too much complex? How we will teach and read that?!
by Aristotle (Chancellor) on Mar 25, 2004 at 03:48 UTC

    (Note: I knew about the method call syntax and was going to mention it — but Larry did, so I don't have to. As is the case with many things. Thanks, Larry!)

    Perl6 is going for more orthogonality than you may have been thinking. We're not going to get @array.length exactly, but a rose by any other name (@array.elems), well…

    Makeshifts last the longest.