Perl 6 Grammars and Regular Expressions
An anonymous reader writes "Perl 6 is finally coming within reach. This article gives you a tour of the grammars and regular expressions of the Perl 6 language, comparing them with the currently available Parse::RecDescent module for Perl 5. Find out what will be new with Perl 6 regular expressions and how to make use of the new, powerful incarnation of the Perl scripting language."
I love regular expressions.
How will this affect people running slash? In a slightly related question, when will Slash support Mod_Perl 2.x, and Apache 2?
But this is slashdot. A slashdoter who didn't build his own computer is like a Jedi who didn't build his own lightsaber!
HXGF*&#$()#P*&ULJKDFHV)(&*#$utrhk:jlhdsf(p*&#$OJDF >KLJDFP)(*$#&pyu:
Crap, I think I just accidentally programmed a web browser in Perl
It would be cool if it didn't suck.
It is good to see PERL focussing on what makes it great. There is no other language, IMHO, that handles text input as well as PERL does. Adding this level of processing just makes it even more powerful.
"...zztop-wants-a-perl-necklace dept."
i do not think that means what you think it means.
4 More Years!!
Perl scripting language? Man, why not just bathe in gasoline and play with matches?
--
Go away YOU PERVERT!
Can we PLEASE just talk about Perl? 5000+ posts about why ruby and python are better from people who have never programmed something important get a little old...
I think the aim here to keep bloating perl until it becomes completely useless as a scripting language. It's already got the most overly complex syntax of any language. Someone forgot that scripting languages do not make good application languages.
Perl 6 will support Perl 5 regular expressions by using the :p5 modifier.
Meaning that it is not backward compatible without modifying your source code.
Note to those who are going to respond "Just install both!": look at the first line of your perl scripts.
I love firing up vi for a cool Perl 6 coding session. And it flies under optimized Gentoo.
I'm sure I'll probably get modded down by some Debian/BSD zealot. They're probably just pissed off because their rigs are so bogged down from emacs and python trying to run together on a non-optimized system.
To this user, the last several releases (5.x) have looked more like opportunities for continuing royalty streams for perl authors (new versions of old books) than significant releases.
"I'd rather be a lightning rod than a seismometer." -Ken Kesey
I'm going to have to rewrite my sig.
perl -e '$_="\007/4`\cp%2,".chr(127);s/./"\"\\c$&\""/gees
ROFLMAOL!
Je t'aime Stéphanie
I'm surprised by the regex grammar. It looks a lot like how I use boost::spirit::rule for parsing regex in C++:
:w { };
// rule for parsing a token string
// 1. Parse declarations
;-)
Perl6---
# note this is just a language example, not an accurate name matcher
grammar Names
{
rule name
rule singlename { + };
};
C++::boost::spirit---
rule split = *(*space_p >>
(+graph_p)[append(tok)] >>
*space_p);
msg "Parsing input\n";
while (!header_ok && getline(input, line) && input.good())
{
tok.clear();
parse(line.c_str(), split);
There are even grammar classes in Spirit.
I sure hope perl6 is faster!
https://www.accountkiller.com/removal-requested
Perl is Visual Basic of the 1990's.
Regular Expressions to Context Sensitive (at least) Parsing. I'm not a big Perl Geek, but I use it on a daily basis.
I can't wait !
Just think....
* More cruddy syntax
* "More ways to do the same thing" (I tell you, if I read that just one more time.....)
* It will be even easier to write complete gibberish and have it run WITH NO ERRORS (even though it's COMPLETE GIBBERISH)
* It will be bigger and cruddier ! (an excuse to buy a bigger drive to load it on to)
* Want to do something complex ? No problem - there's a one-liner that will do it !!!
* Want to do something dead simple ? No problem - there's this huge bloat of a module that you have to install. Oh yes, it depends on half a dozen other modules too. That's what makes Perl so "good" (?!)
No, I really can't wait !
Perl is OK in one or two areas. ie - the areas that everyone quotes - string handling and regular expressions.
The thing is, the world has moved on and this stuff is available in a lot of scripting languages. And they are smaller, they have better syntax (they could NOT POSSIBLY BE WORSE !) and they make more sense.
Perl is for people who don't have a life and can't admit that it was an ok idea that went horribly wrong.
Correction: Perl is the Visual Basic of the late 1990's.
Note to those ready to mod me Troll/Flamebait: I'm not trying to pick on Python, I just happened to be acquainted with this candid quote.
The grammars appear to be in a class called "context free languages"(CFGs). Some CFGs are ambiguous in the sense that a given "sentence" can be derived from more than one set of rules. Traditional tools such as yacc/bison tell you where there is ambiguity in your rules - even then it isn't always easy to remove the ambiguity (trust me on this). If the Perl 6 system doesn't help the programmer debug the grammar he/she will not be happy when the parsing doesn't work as expected.
In addition, the article ends the description of features with "And much more...". It appears that Perl 6 grammars are more powerful than CFGs. If they can simulate a Turing machine...
No electrons were harmed creating this post, though some may have been subjected to electrical and/or magnetic fields.
Oh My God! This will make Perl code look really crazy. I'm managing 15 kSLOC Perl SW an 50 kSLOC PHP SW. Making changes to Perl code is at least twice as hard and requires much more time to re-study the code (and that both SW are written by myself with trying to keep the "code style" like no $tmp vars etc.).
Perl is usefull for 1-100 lines "maintenance" scripts but writting some reall SW in it just sucks...
Ignore me all you want! At least the voices in my head listen to me. ;->
We all know that reusability is a BAD thing. If you code in Perl you never have to worry about making your code reusable, since there is no chance in hell of ever reusing it.
:)
Perl - brings the idea of reinventing the wheel to a whole new level
A whole morning of Taco and no Dupes...OMG the world is ending. IT IS THE SEVENTH SIGN! Zeus, Jehovah, Buddha, Jim (for agnostics), SAVE ME!!!
Oh yeah. Larry and Co. went off the deep end with Perl6. I mean now they DO have the kitchen sink in there.
That's what happens when you take a philosophy "more than one way to do it" and run with it.. straight off a cliff.
It is impressive the way they unify everything though. I guess if you can't make a language simple and elegant, you might as well try and make it consistent.
And the new regexp syntax is sorely needed. Regexps have grown up now and the syntax needs to be rethought. So I hope the other less confusing languages like Ruby will pick up the new regexp syntax someday.
I would also love to see a relational query language (NOT SQL THOUGH.. maybe something like Tutorial D) embedded right in the language like regexps are... but that's a discussion for another time. Let's get some real relational databases first.
Anyway, Perl6 is quite fascinating, but slightly insane.
Did you ever go drinking one night, but decide to NOT drink and just pull out a lawn chair and watch what people are like when they are drunk? That's how I feel watching Perl 6 evolve from the cozy comfort of Ruby. Lots of fun as long as nobody pukes on me!
'whereas in Perl 5 you can match "hello there" with "hello there" itself, in Perl 6 you'd have to ask for /hello <sp> there/ instead.'
Then: grammar English { rule name :w { <singlename> <singlename> };
rule singlename { <[A-Z]><[a-z]>+ };
};
Shouldn't this be: "{ <singlename> <sp> <singlename> };"?
They're putting dimes in the hole in my head to see the change in me.
my Amiga 500 can do more stuff in 512K (yes, that's kilobytes sonny!) than you could ever dream of with your p4 and "optimized" gentoo, and with only a M68000 7MHz cpu. yes, bow down your heads silly gentoo fans for your OS doesn't hold a candle to the glory of what Amiga achieved almost 20 years ago. hell i bet your mouse pointer slows down when you format a floppy disk. pah! you silly people!
(I'm a recovering language bigot so I can say this. :-P )
I'm studing seriously the posibility of tackling a whorty coding proyect, the rewriting of the entire LINUX kernel on a languaje very much but not unlike C and was considering doing it in C-INTERCAL but after seing things like this http://ozonehouse.com/mark/blog/code/PeriodicTable .html , I changed my mind and will use PERL 6 instead.
And I have prayed unto You, O Lord U**X in the time of the Will of Linux.
Perl 6 grammars are a full citizen of the language on a level with subroutines and classes (loosely speaking, in Perl 6, rule:grammar::method:class, actually). They're effectively Turing-complete as a result, since Perl 6 is obviously Turing-complete.
Perl 5 "regexps", by contrast, are more of a specialized second language bolted onto the side (I use quotes since Perl 5 regexps are already marginally more powerful than "pure" regexps).
DNA just wants to be free...
Actually, I for one tried to learn perl once.
I tried to absorb the syntax docs one afternoon, but it gave me nightmares. Literally. It was as if the C-programming-part of my brain was in conflict with the oddball operators and constructs presented in the perl language. Ever since I've been haunted by perverse unreadbility of it all. I liken the experence to attempting to think in brainfuck.
So by this I know for a fact that perl is Not My Thing(tm).
Now, a more objective reason as to why perl isn't generally a good language (but not completely bad) is evident in the very syntax of perl itself.
Useful code shouldn't be as inscrutable as its compiled counterpart since that defeats the whole point. Perl is a language, so it follows that it is a communication medium. By that it should be able to communicate something to a party outside just the author and the perl interpreter. It can accomplish this, but not without the reader having to go through the mental gyrations of what could be best called linguistic decompression. The language has this tendency to impose this extra step to yield the information communicated. Simply put: it gets in its own way.
Now, useful programs on the other hand follow a different set of criteria of course. I've used perl-coded stuff online all the time, and enjoy its reliability and speed.
I'll give credit to the fact that perl is compact, terse, to the point and has a reputation for string manipulation. It fills this niche rather well, and is a prime example of the being "the right tool for the right job".
IMO, "the right job" for perl is about 2% of all programming tasks out there. This is evident by the fact that even though perl was the prominent CGI language of the mid-nineties, it lost the overwhelming majority of that interest with alarming speed.
As for python, I'm sure it fills a niche too... whatever the hell it is.
Inconceivable!
I find that reaction to Perl by people familiar with highly structured languages is common. I think this is because Perl has things like weak typing and overly flexible syntax, things that make experienced programmers vomit in their own mouths. But what's great about Perl is that you CAN have strict grammar, and you CAN have strong typing, if you desire. It's just not required.
This makes Perl very strong as a teaching tool for beginner programmers. They can start out writing loose, messy code that gets the job done, and slowly work towards stronger, more structured language. People that wouldn't have the logical dicipline to jump directly into C++ can use Perl to learn logical programming one concept at a time, and eventually be ready to grasp required C++ concepts like objects. But you'll find that people raised on Perl, even if they primarily program with C++ or Java, always come back to Perl for the quick scripting or text-processing tasks.
... so when I need a webserver, I just
/dev/urandom | perl
$ cat
It usually works in 3 tries or less.
HAND.
Nah, you haven't figured out yet when the tail should wag the dog. In Perl culture, if you're gonna go and rename something because it's inaccurate or unwieldy, you have to have the hubris to come up with a new name that is shorter and handier. That's how "associative arrays" turned into "hashes" in Perl 5. And if you were up on Perl 6, you'd already know that "regular expressions" are turning into "rules" (though people are still allowed to say "regex", of course). While Perl likes technological hacks, Perl loves cultural hacks.
http://shit.slashdot.org/article.pl?sid=04/11/08/1 511201
Yes, it does include a lot of symbols, but there is payback to learning them, and really most programs won't use much beyond $ % # () [] {}. Unlike some languages, Perl is not what I would describe as a 'bondage' language. If you want to program sloppy, you can program sloppy. That's fine by Perl. And this generousity is what gives Perl its bad reputation. This is funny since I and most knowledgeable Perl programmers can write perfectly clear and maintainable code. The way we do this is no secret--it's just by commenting appropriately, using meaningful identifier names and following the Perl style guidelines.
People can mock Perl all they like, but it is still a widely used powerful programming language and I am more productive in it than any other language. As a parting comment, a Cisco employee once told me (off the record of course!) that "Cisco would fall apart without Perl".
The grammar and rule syntaxes are very reminiscent of BNF's and EBNF's although maybe not as descriptive.
Vivin Suresh Paliath
http://vivin.net
I like
PERL is a great language. Ugly yes, but once you get used to it there's is no going back to C/C++ or JAVA, at least in a mostly tool-less environment like UNIX. For many classes of programs, the productivity you get from PERL is an order of magnitude greater than in C/C++ (some would argue that I just need to learn the STL classes....). I think most of this is because PERL is interpreted....the code, debug, compile cycle is significantly shortened. You also never wonder what version of the code you are running.
PERL 6, however, seems to be dead. I've been following its progress for a couple years now and it is going almost nowhere. The decision to move to a bytecode interpreter looks like a huge mistake. Most people are fine without the bytecode interpreter and it has split off dev resources from the issues that would help your everyday user -- "syntactic sugar". For instance, PERL as it is doesn't have named function parameters, each function is just passed an array of parameters (unlike in pretty much every other language I know--C, LISP, Java, etc)). Adding this functionality would presumably be simple to do, without implementing a bytecode interpreter. OO support is also lousy in the current PERL.
The feature request framework was also lacking. Everything went up to Larry Wall, who decided things basically as God. I saw at least one simple and powerul thing dismissed out of hand -- a built in loop counter. So often in while loops it makes sense to have a counter of the iteration #...this requires at most a single addition for each iteration but was skipped.
The stated goal of PERL6 was improving XS, but this doesn't require a bytecode interpreter either.
Of course, this is all running off volunteer labor so I shouldn't complain too much!
For some reason, useless uses of cat really irritate me.
--
Personally, I find the < form uglier -- I'm not sure why, but I guess it has something to do with the pipeline
...
...
:)
$ cat bla | prog1 | prog2 |
"flowing" purely from left-to-right, as opposed to
$ prog1 < bla | prog2 |
where input flows from right-to-left then right again.
Also, the former is marginally easier to modify if you need another stage of processing before prog1.
To each his own, I guess.
HAND.
Regular Expressions to Context Sensitive (at least) Parsing. I'm not a big Perl Geek, but I use it on a daily basis.
No, the grammars this system parses are a subset of the context-free grammars (if we exclude any context-sensitive behaviour created at a higher level using actions).
Freedom is not increased by mere diminuation of government. Anarchy is freedom for the strong and slavery for the weak.
The purist Computer Scientist in me loathes it.
"Much as I hate to say it, the Computer Science view of language design has gotten too inbred in recent years. The Computer Scientists should pay more attention to the Linguists, who have a much better handle on how people prefer to communicate."
--Larry Wall
Spine World
Cold Fusion, Visual Basic, Matlab, C, C++, Javascript, Java, C#, XSL, SQL, and PHP.
But now that I'm stuck on mod_perl2, I find myself choosing Perl again and again for any purpose it might fill. And it does the job damn well. I can endure the other languages my work requires... They get the job done. But every time I go back to Perl its like a breath of fresh air. It really is a wonderful language. CPAN and cross-platform really seals the deal. Even the simple OOP system in Perl 5 is a thing of beauty, despite being a hack. The syntax grows on you too... If I could program Perl exclusively I would do it in a heart beat.
Nobody can disrespect Perl out of ignorance and call themselves a software engineer.
To blog is sublime
I'll have to dig out my copy of Aho and Ullman and brush up. I've not taken a good look at the "strength" of the new matcher.
I'm not really advocating a change of name from regex, only to recognize how much more powerful the matching has become.
I have really thought on how to get strong typing in Perl 5, and i think it's impossible. With strong typing I mean full compile-time verification that wherever a variable (or constant, parameter, array slice, any piece of syntax that denotes a value) is asserted to be of a certain type or in a certain class, it is 100% certain that all values this variable can possibly assume will indeed be of that type / in that class.
For arbitrary Perl 5 code this is obvious, but I don't want it for arbitrary code: I want it for my own Perl code. I want to be able to provide type/class definitions for all the arguments and return values of all subroutines that appear in a particular piece of Perl source code (both my own and calls to subs defined elsewhere) and have the compiler verify: assuming that all these foreign subroutines satisfy the typing specified here, are my own subroutines 100% guaranteed to satisfy it as well?
There doesn't seem to be a way to do this with Perl. Perhaps there is something in the Devel::* namespace now which is suitable? It's been a while since I tried this (and gave up on programming larger projects in Perl for that reason).
How's perl dangerous?
;).
In my experience (as a IT security guy) C and PHP are more dangerous than perl.
C - "runs arbitrary code of the attacker's choice" given _common_ stupid programmer mistakes.
PHP - developers fond of features that encourage bad/insecure ways of doing things - e.g. magic quotes, global track vars. Take away such popular PHPisms and PHP starts to look like perl