Exegesis 6 (Perl 6 Subroutines) Released
chromatic writes "Perl.com has just published Damian Conway's Exegesis 6 which gives practical examples demonstrating how to use the new subroutine and method semantics in Perl 6. This is the companion to Larry Wall's Apocalypse 6 which discussed the changes planned for subroutines in Perl 6."
- Everyone in the world had a chance to submit RFCs
- Larry is taking each section of the 3rd edition Programming Perl and turning it into a white-paper on the way Perl 6 will work, using the RFCs that touch on that section of Perl as a sort of shopping list, and accepting, modifying or rejecting them as needed. These are called the Apocalypses.
- After an Apocolypse is out, Damian starts working on some real-world examples to make it all more concrete. These are called the Exegeses. Sometimes these also have examples of syntax and semantics that have been worked out via the mailing lists
- Eventually, this will lead to the Design Documents
Hope that helps clear this up for those who aren't sure what's going on when they see a new Apocolypse or Exegesis come forth.The one thing that I always found unpleasant when moving between languages was the keywords... so, I picked up a C book, migrated to C++, then Java, picked up PHP along the way. Everything was fairly similar with keywords and syntax, and then perl threw a monkey wrench into the mix. I've never looked at python, are there similarities there or are the perl gurus guiding us through their path of enlightenment?
Python syntax is close enough to C, C++, Java et cetera not to cause most people any problem - except in the few places where it isn't, of course!
John Roth
HOWEVER, that being said Perl has a huge advantage over the keyword restrictions of most languages. I'll show you a sample of some code, and you tell me if you can see what the advantage is:The same goes (to a slightly lesser extent, since you don't *have* to use the prefix-sigle &) for subroutines and all of the other miscelaneous Perl data types that can be named (obviously those that cannot be named like stashes never conflict with a keyword).
Actually the parent is wrong. The bahavior os f2k($temp) is different than f2k($temp is rw) in that Perl will assume a constant variable by default. So no, you don't *have* do, unless you want to make your parameters read-write. Which could lead to less lines and variables later on.
Moderation: Put your hand inside the puppet head!
In Perl, you are guaranteed that your variables will never conflict with keywords. Not ever. Not even if you try.
What's the big deal about that? In Python, for example, you can do the same thing with much less fuss:
or with your positional parameters:
The same string conversions happen. 'a' is still an integer, and the language knows it. You just don't have to keep typing 'int' and 'toFoo()' over and over.
I've never seen a language with so much syntax. Perl 5 had more than enough, now they've more than doubled it.
:= and ::=, ~=, ~~, .... = does assignment, := does binding and ::= works at compile time and is normally used to define types and such, ~= is pattern matching, and I have no idea what ~~ does.
...
You have { } for blocks, and for automatically parameterized blocks (ie. anonymous functions).
You have =,
You have the new <== and ==> pipeline operators. They are dataflow operators. Like so:
$foo ==> my_func ==> $bar;
is the same as
$bar <== my_func <== $foo
is the same as
$bar = my_func($foo);
is the same as
You already had the $,@,%,& to prefix variables with.
You have more uses for * now, as in slurpy arrays and splicing. As in, the * can make an array parameter slurp up all the remaining arguments, or it can make an argument flatten into a list of arguments.
They've added some wierd << foo >> syntax that I didn't even bother to read about as I was in syntax shock.
They've added ^ which indicates that a variable in a block is actually a parameter and therefore the blocks is actually a parameterized blocks (ie. anonymous function). So, now you can't tell if something surrounded by { }'s is just a block of code or whether it's an anonymous function. Although, I don't think this is a problem as it's usually obvious from the context.
And I didn't even read to the end of the paper!
Makes me want to go write some Lisp, which is perhaps the antithesis of Perl. Lisp has the maximum possibile flexibility through having the minimum possible syntax. Perl originally had little flexibility, now they are trying to add more by adding more syntax. The problem is, if they want to get anywhere near Lisp-level flexibility with this method they'll need to move to Unicode for the syntax!
Justin Dubs
Parrot has both today. (Okay, it just picked up the standalone binary compiler a couple of days ago.)
how to invest, a novice's guide
When they say "keywords", I'm sure they meant "functions in the global namespace".
Actually, the following code (in Perl 5):
;-). I haven't puzzled out the Perl 6 stuff enough to know what would happen then (probably a compile time error in assigning "bar" to $foo if $foo is declared as holding only numerical types).
$foo = "bar";
$foo++;
Result in $foo holding the string "bas" right now
It's a strange world -- let's keep it that way
It's not just you, but about 80% of the syntax stays the same. Much of the rest requires a few parser rule overrides. See ... And Now For Something Completely Similar, also by Damian.
Backwards compatibility is a huge concern. That's why Ponie exists and why Dan's so careful about supporting Perl 5 semantics on Parrot. (As well, I expect 80% of the core Perl 5 tests will port to Perl 6 with surprisingly little work.)
how to invest, a novice's guide
I don't think it is any more different from Perl 5 than Perl 5 is from Perl 4. Huge amounts of extra stuff (most importantly objects and nested data structures) were added from 4 to 5, together with quite a few syntax changes.
However, backwards compatibility will be more of a gap, because perl 5 is pretty much source-compatible with perl 4, but it doesn't seem that 5 -> 6 will be the same. (No, having a separate interpreter specially built to run older scripts doesn't mean source-compatible in this sense - I'm talking about the language itself.)
-- Ed Avis ed@membled.com
Your terminology, using 'variable' to refer to a whole typeglob slot, is nonstandard in the Perl world. Most programmers (and Larry himself AFAIK) would say that $x is a scalar variable and @x is an array variable. They are both variables and both different.
Referring to the whole typeglob with *var is rather esoteric (not saying it's never used, just it is used far far less often than accessing variables normally), and when you do use it, you talk about typeglobs not variables. *var is a typeglob, which brings together several different variables of the same name.
At least, that is the terminology almost everyone uses.
-- Ed Avis ed@membled.com
Java solved that problem many years ago, and Smalltalk solved it many years before that.
How to solve most of our problems: 1.Lots of nuclear plants. 2.Cure aging.
The names are a running gag on church-latin, that interconnects Larry's linguisticism, Damian's eclecticism, and the monastic themery of the Perl Monks' alternate retroynm for .PM. Larry's Apocalypses are not apocalyptic in the common figurative sense (although the neo-Luddites who think the only improvement on Perl5 is PHP or Python may think so), but are the Revelations of the gur, which is the original sense of the word, before it came to be used to refer to the particularly apocalyptic content of St.John's Revelations also called Apocalypse in the latin. The churchly Exegeses are non-canonical explanations of the deeper meanings of the canonical texts. And of course, synopses are shorter summaries, like Cliff Notes (TM) or Master-Plots (TM), and were originally applied to religious writings of course.
Would that everyone were so blind!
I think I have a pretty good sense of Perl 5, Perl 6, and Parrot.
I also know how many Perl Foundation dollars have been spent to get Parrot where it is today. It might be enough to hire one of the top .NET folks for most of a year. For the money, Parrot's a bargain.
how to invest, a novice's guide
Parrot's been around two years, not three. The oldest Perl 6 code I can find running on Parrot goes back one year.
Perl 6 isn't completely implemented on Parrot because Perl 6 isn't completely designed yet. Perl 5 isn't completely implemented on Parrot because no one's had the right combination of time, talent, and funding to implement it yet. The same goes for any combination of Perl and Parrot you care to mention. As of last month or so, there had been somewhere around five man years of Perl 6 and Parrot work funded.
Paying one developer to work on Parrot for a year and a half would double the amount of full-time contributions.
The parallels to Mono and DotGNU are inappropriate. Not only are they reimplementing something that's already been designed and implemented once by legions of funded developers at Microsoft, Ximian pays people to hack on Mono.
how to invest, a novice's guide
Nice try but no. See apocolypse 1, you need a keyword to be in Perl 6 syntax otherwise it falls back to Perl 5 for the entire file. So absolutely nothing happens.
Oh so?That does not seem very nighmarish to me. What's more, manipulating complex data on the fly is trivial in Perl:which would be an array of 4 elements, of which the fifth element is a hash of two elements, the values of which are themselves arrays. Not that hard is it?
There is the container-access syntax that I find rather messy, but even that's not so bad, and it goes away in Perl 6 entirely, again without impacting that very clean way of identifying variables that lets you do things likewith one, uniform syntax.
No, I pointed out a few already, and there are others. You simply happen to disagree. That's fine too. Perl is about accomodating disagreement in a single language, and that's hard to do with a limited keyword set.
You're carrying type-information around everywhere you go, because you think it allows you to add keywords
I've pointed out elsewhere that type information and variable glyphs are different. They do have an association to type, but it's a loose one.
For example:Here you have three variables. One is a simple scalar. One is a reference to an array. One is an object that represents a socket, connected to the HTTP port of a remote server. The $ doesn't tell you a whole lot about type, it just indicates a scalar access-mode.
Do you know why C doesn't add new keywords
*I do*, but I wonder if you do....
C does not add new keywords because it is a syntactically simple language, and that's part of its attraction. Any attempt to change that (e.g. the way C++ did) would destroy that, and would need to justify such a change against the benefit.
I think that Perl does justify this increase in complexity, though to most outsiders that's not obvious. You really need to be able to think in Perl before you understand just how valuable all of that syntax is.
At one point, I knew C so well that I thought in it. That was long ago, but I still remember how powerful that was.
When I learned Perl well enough to think in it, I was introduced to a new kind of programming. I was suddenly able to write in a few lines of code, what would have taken pages and pages of C, even with a good set of libraries. Just the ability to say:dwarfs the abilities of C.
That's not to say C is useless. I still use it from Perl all the time, via XS. If I had to write a device driver or any other low-level code, I would still use C. But for your run-of-the-mill software, Perl is leaves low-level languages, and even most high-level languages far behind... at least from my, admittedly limited, point of view.