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.
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...
We are talking about Perl, not (L(I(S(P))))
Ok, folks; choose your topic:
a) Is it called GNU/Linux or Linux?
b) Emacs vs Vi
c) "Ok" goes on the left, "Cancel" goes on the right.
d) Security is based on market share - NO! Apache is more secure despite bla bla bla!
e) 45 RPM LPs sound better than reel-to-reel!
It would be cool if it didn't suck.
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.
You have GOT to be kidding!
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
Haha, yeah, I know. I was pulling crap out of a hat at the end there, but I knew I had to provide at least one retarded audiophile option.
It would be cool if it didn't suck.
Damn, I knew I forgot one on that last post I made.
It would be cool if it didn't suck.
I'm going to have to rewrite my sig.
perl -e '$_="\007/4`\cp%2,".chr(127);s/./"\"\\c$&\""/gees
Those of us that use Perl as more than just system duct-tape know it's a programming language. Perl 6 will make that even more clear by being based on OO fundamentals rather than being a procedural language with OO tacked on top of it. This is just another debate that makes the OS community look like a bunch of freaks and zealots... just like the GNU/Linux thing. Get over it and start focusing on what the software does, not how to classify/name it.
You have enemies? Good. That means you've stood up for something, sometime in your life. --Winston Churchill
Yeah, no kidding. Everyone knows that an LP runs at thirty-three and one-third RPMs.
Personally, I think that the 72RPM phonograph records sound best, but that may just be a reflection of the kind of music that's most often found on them. They certainly have more character!
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
I've got a fully multithreaded perl script running under Win32. It wasn\'t too bad to write but some parts sucked. One of the things sucked because Win32 doesn't support alarm() calls and you have to manually poll sockets and I hate that shit, or use vec() and that's just insane (how many people understand how vec() works anyway???) The other big thing that sucked was the crappy mechanism for sharing complex data structures between threads. All's honky-dory if you're just sharing a scalar variable, but don't try a HoH or anything like that cause you'll find out that there's no auto-vivification, and you have to manually create the data structure in every thread that needs to access it, and that right there leads to lots of possibilities for "interesting" bugs to show up (it's not very fun to code or pretty to look at or understand once it's done).
But anyway none of that is really here nor there, but I just wanted to comment that Perl "scripting" isn't just CGI forms and stuff like that. You can really do complex applications in Perl. It's a full-featured language, portable (moreso that even Java, just look at the list of archs in the Configure.sh script), and able to handle most tasks that don't require a tiny memory footprint or direct CPU register manipulation.
Regular Expressions to Context Sensitive (at least) Parsing. I'm not a big Perl Geek, but I use it on a daily basis.
-- Mr. Luddite
Generally, bash is superior to python in those environments where python is not installed.
Of course you meant 78 RPM, right?
It would be cool if it didn't suck.
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.
We both forgot to mention Macs though. Suprising, since there are literally thousands of people using them these days :)
...then it will stop being a good duct tape for systems.
--Matthew
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.
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
Not all LPs were 33 1/3, some were released on 45 (and in some occasions, both) for 'improved quality'. Take for example, Metallica's Master of Puppets, released on both 1 33 1/3 RPM LP, and on 2 45 RPM LPs.
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.
(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.
Those of us that use Perl as more than just system duct-tape know it's a programming language.
Those of you that use Perl for more than just system duct-tape should have their head examined.
Note title.
Inconceivable!
Erm...yes, of course...it's been awhile.
Get over it and start focusing on what the software does, not how to classify/name it.
I disagree with this comment classifying and naming software makes it sound alive. I think we should describe or label it.
What is a floppy disk?
this sig limit is too small to put anything good h
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.
Those of you that don't grok Perl should have their posting privileges revoked. At least for this thread! ;-)
!ERR: Signature not found.
If you assume that languages can't scale both up and down simultaneously, please don't try to design any computer languages near me. Thank you.
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!
I prefer the which-time-and-date-module-is-best argument. I like DateTime.
Cut that out, or I will ship you to Norilsk in a box.
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.
I believe that singles were often 45's.
/Too young to remember.
"I use a Mac because I'm just better than you are."
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
Since you claim to have written both codebases, perhaps your difficulties say more about your ability to program in Perl (or any language) than about Perl itself. I've written a lot of Perl code and I couldn't think of (re)writting in a language where all variables are global (no namespaces) or other poorly thought-out "features".
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
"I disagree with this comment classifying and naming software makes it sound alive. I think we should describe or label it."
Sound alive? How about "toe tagging" it then?