Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

From http://perlgeek.de/en/article/mutable-grammar-for-perl-6

What I could understand is that since the grammar of Perl 6 is written in Perl 6, One can override the grammar and change some of the syntax itself? Am I right if say this?

What level of flexibility would that be? I mean one can probably change keyword names like 'for' could be changed to 'from' , Or the sigils could be interchanged like '$' for '%' and viceversa,Converting all the keywords to capital letters etc. What other possibilities can be achieved and upto what level is it available

This seems to be a very powerfull feature which no other language is having currently.

Replies are listed 'Best First'.
Re: Perl 6 grammar question
by Corion (Patriarch) on Mar 12, 2010 at 07:48 UTC

    The main thing is that you can introduce new keywords, something which is not easy to do otherwise. If Perl 5.8 had had that feature already, you could have implemented the given keyword as a Perl module.

    Of course, having a mutable language is nothing new - Lisp had it 40 (or is it 50) years ago with its macros.

      I didn't know that lisp had it, thanks for mentioning it here. However in Perl 5 we are introducing it through a module(.pm) file which is pretty much different than controlling the parser itself. Apart from lisp and Perl 6 which other language has this feature(Modern languages in wide use today like Python, ruby, Java etc.)

        However in Perl 5 we are introducing [given] through a module(.pm) file which is pretty much different than controlling the parser itself.

        That's wrong on two levels.

        First, all the module does is to flip a switch that controls whether the parser treats given as a keyword or not. feature most definitely controls the parser itself.

        Secondly, it makes no sense to say that adding keywords dynamically is a good thing and to say that adding keywords using a module is a bad thing. It's a contradiction.

        I'm not aware of any "modern" language having that feature, at least outside of the languages without much syntax (Scheme, Lisp derivatives), where it is easy to introduce new forms or which have (real) macros as a built-in language feature.

Re: Perl 6 grammar question
by moritz (Cardinal) on Mar 12, 2010 at 12:38 UTC
    What I could understand is that since the grammar of Perl 6 is written in Perl 6, One can override the grammar and change some of the syntax itself? Am I right if say this?

    yes

    What other possibilities can be achieved and upto what level is it available

    It goes very far. There is basically nothing that you cannot change. By overriding the <EXPR> rule (or some other fairly top-level rule) you can substitute the complete grammar with your own, if you feel like.

    However the question arises to which extend you can change the grammar without changing the compiler backend. I don't think that questions is fully answered yet.

    Perl 6 - links to (nearly) everything that is Perl 6.
Re: Perl 6 grammar question
by almut (Canon) on Mar 12, 2010 at 09:11 UTC
    keyword names like 'for' could be changed to 'from'

    ...and goto could finally be replaced by come from — as originally proposed in 1973.  (see also)

    Err, wait... we already have it in Perl 5, albeit as a source filter.

    ;)