Exegesis 2: Damian Conway On Perl6
sumengen writes: "Damian's writing a series of articles parallel to Larry's Apocalypses.
These 'Exegesis' articles will show full perl6 programs, with
commentary exlaining the new features.
The first Exegesis (numbered 2, to keep in sync with Larry) shows a
perl6 version of a binary tree program from the Perl Cookbook.
Get excited to see things like:
my int ($pre, $in, $post) are constant = (0..2);"
my int ($pre, $in, $post) are constant = (0..2);"
Damian Conway writes:
The first thing you'll notice is that reports of the diamond operator's death have been greatly exaggerated. Yes, even though the Second Apocalypse foretold its demise, Rule No. 2 has since been applied and the angle brackets live!
I assume this means that Larry has had a change of heart since he wrote Apocalypse 2, but what is this mysterious "Rule No. 2" that has been invoked?
--
I had a really nice response to this that would have been extremely helpful, but the guys at slashdot seem to think perl code is random characters:
:)
Lameness filter encountered. Post aborted.
Reason: Junk character post.
Kind of funny, since it's all written in perl. Kudos, rob- you've managed to stifle any discussion about perl code.
Er. the semicolons in odd places like "if; br(T, tree(T), tree(T))" is pretty obfuscated. Yes, you may say there is a good reason for it, but then there is a good reason for Perl's oddities as well.
> I'm surprised Perl doesn't support the GO-FROM-idiom yet
_ Pr ogramming.html
You're thinking of "COME FROM".
See "A Linguistic Contribution to GOTO-less Programming"
http://neil.franklin.ch/Jokes_and_Fun/Goto-less
It's been implemented in INTERCAL.
http://www.tuxedo.org/~esr/intercal/
--
rant
How about:
$*ARGS is chomped;
Maby it's just me, but I fear that setting properties to variables that affect how fuctions work on them, will greatly decrease the quality of code, available.
Let's just face it, not everybody has even heard of Dijkstra, let alone know how to write 'proofable' programs.2 C3AF4F2snlbxq'|dc
--
echo '[q]sa[ln0=aln80~Psnlbx]16isb15CB32EF3AF9C0E5D727
echo '[q]sa[ln0=aln80~Psnlbx]16isb572CCB9AE9DB03273snlbxq' |dc
Urrr.. I tend to use Perl a lot.
Ya know, it's quite easy to pick up (I got up and running in an afternoon on the basics).
The prefixed identifier is pretty useful as a memory aid, so that you are ALWAYS aware of what type you're dealing with (scalar, array, hash, sub, or typeglob).
To learn what these are, you read one page in a book, and all is clear. Now, how difficult is that??
If you're having trouble extracting values out of variables, then I think you have a weird view of 'difficult'. Pulling a value out of a deep struct in C can be difficult, but using $_ being difficult? Bah.
Still, if you don't like it, fine. Your choice. But, please don't keep saying it's so difficult.
I taught my Girlfriend to use Perl in a day (at the basics), and she's never learned a programming language in her life prior to this. She's now sailing away in it happily.
Cheers,
Malk
Or functions like
touch (my $bitch) and die;
ZOMG I WOULD LOVE TO KNOW ABOUT YOUR FEELINGS ON MACINTOSH VERSUS WINDOWS, VI VERSUS EMACS, AND HOW YOU'RE NOT A DORK
Perl may look confusing, but there's nothing like having to work in VB for a week to make you miss the raw power Perl provides.
Some of these language changes disturb me too, but I trust Larry to ultimately make it fairly simple to transition from perl5-think to perl6-think. The transition will break a few things but it sounds like it will increase the power of the language by about as much as perl4 to perl5 did.
Caution: contents may be quarrelsome and meticulous!
Your right to not believe: Americans United for Separation of Church and
if $bitches = $da_shit, do $nasty_stuff
--
--
"Outlook not so good." That magic 8-ball knows everything! I'll ask about Exchange Server next.
10 PRINT "Fuck You!"
20 GOTO 10
Be sure to pipe the output through lpr.
--
--
"Outlook not so good." That magic 8-ball knows everything! I'll ask about Exchange Server next.
Do you really expect to see three variables initialized to 0, 1 and 2 in a tight inner loop? The ridiculous PL/I initialization syntax sought to be concise, and this was achieved at the expense of clarity. This Perl construct seems the same. Just about any syntactic monstrosity can be justified on the grounds of performance, but you have to wonder how much it's really going to help in practice.
I was also happy to see Basic's "dim" recycled.
Really guys, haven't we learned anything since oh, I don't know, 1965?
Now in Perl 6, one can have such syntax as: my int ($pre, $in, $post) is constant = (0..2);
and: $ARGS is prompts("Search? ");
With the advent of this new "is" construction and the use of passive voice in the code, I think that the following should also be added:
This would allow for such conventions as:
$*ARGS be chomping;
"LibCGI.pl" is being required;
(or if one wants to be smart:)
recognize $foo!;
Just a thought.
Has anyone else out there sort of grown up with Perl during this dot.compost era and now started to check out C and the real guts behind ''world domination?''
I'm finally getting into C by taking a night class at UCLA, and my god, this stuff only gets cooler and cooler. To see the community RFC type thing go on with Perl6 and to watch/hear/readof the ISO committee floundering with other languages is very interesting too.
Of all the uninspiring things happening with government, the economy, environment, etc these days, I really recommend that any inclined kid such as myself out there get back to basics and check out what their local community college/college extension has to offer. I have, and every time I walk out of class it's like "oh, no shit, that's friggin sweet." Maybe it's just me, but for some of these things, it's just easier to be in an engaging classroom environment rather than to be all by your lonesone with Conway's ''OOP.''
Anywho, back to coding..
I know you're a troll, but from O'Reilly
Try comp.lang.ada. It's swarming with Ada fans, many of whom would be happy to explain why they love the language so. Ada Home and AdaPower both have quite a bit of information and evangelism (the former is a bit of a 'classic', though).
Does Perl still support GOTO?
God, I love that command.
Feed the need: Digitaladdiction.net
Will it? I thought python was whitespace dependent ... :-)
"What I look forward to is continued immaturity followed by death."
example (this is lifted straight out of the book)...... The 'while' loop.......... ;
while ($tickets_sold
chomp($purchase);
$tickets_sold += $purchase;
}
If it was taken from the book, why are there 2 syntax errors in the first line? Try again.
This isn't actually that good an example of what my gripe is, but look at it !!! I mean, what's wrong with a READABLE example like..... my ($blob) = 0; while ($blob 10) { print "$blob\n"; }
--
"that's not encryption - it's a new perl script that I'm working on..." - from some Matrix parody
Ooops, hit submit when I meant preview
;
example (this is lifted straight out of the book)...... The 'while' loop..........
while ($tickets_sold
chomp($purchase);
$tickets_sold += $purchase;
}
If it was taken from the book, why are there 2 syntax errors in the first line? Try again.
This isn't actually that good an example of what my gripe is, but look at it !!! I mean, what's wrong with a READABLE example like.....
Your syntax is wrong, how about this?
my ($blob) = 0;
for $blob1 ($blob..10)
{
  print "$blob1\n";
}
Your arguments would have much more power if you actually had ANY IDEA what you are talking about.
--
"that's not encryption - it's a new perl script that I'm working on..." - from some Matrix parody
$*STRONG being the force;
After reading the page (ouch, my head hurts), I'm surprised Perl doesn't support the GO-FROM-idiom yet. It'd help alot in obfuscating the code more:
/* jumps to all "go from LABEL1"s in the code here */
LABEL1:
.....
go from LABEL1
By using multiple GO-FROMs you can even make threads! It's powerful, intuitive and obfuscated. Just the right thing for Perl 7.
If you think "go from" is too elaborate, you could probably use ${LABEL1}-> instead. Unless that's taken of course.
- Steeltoe
http://www.debunkingskeptics.com/
Perl can definitely look strange, but you learn over time just how much is possible with the top row of your keyboard, and in how little space it can be done. If you want an example of *readable* Perl code, check http://daveb.net/Code/Perl/phonecode.html. It's not as difficult as it seems. Eventually, you will cackle with glee while you hold down the shift key and bang away at that top row: @#$(&^@)#$&%_. Learn Perl. Love Perl. Be Perl. Then go on and learn something else.
synatical (sic) declaration is not the same as typing - it is only an aid to the compiler.
Syntactic declaration is highly valuable to the maintenance programmer. It makes a believable statement about a data object. Misery is reading a program in a language where there are no type declarations on function parameters, but types do matter. Perl 5 comes to mind. Effectively, parameters have types, but nothing but comments (if any) tells you what they are. This is especially painful for object-oriented Perl. Smalltalk had the same problem. Attempts to deal with this problem via comments usually fail, unless some stringent management regieme is imposed. Such a regieme is usually worse than a declaration system.
Declarations force a nonlinear thinking style on programmers; you're continually jumping back and forth between declarations and executable statements, which are often in physically different places. It's unwieldy in text editing, and distracts from thinking about the executable code. And then there are the "header file" / separate compilation consistency problems. These are the issues that drive programmers to languages with lightweight or no declarations.
On the other hand, dynamic typing tends to defer error detection until the program blows up in operation, instead of detecting it during compilation. Some people think this is good, and some don't. As program size grows, it's more of a problem.
These are the sorts of issues that affect user acceptance. It helps to think of programming as a user interface problem. In fact, user interface testing of programming language constructs, where programmers are videotaped programming and their keystrokes logged, could be quite valuable. I've not heard of that being done.
Wash, rinse, repeat.
C went through this evolution, taking about 25 years to do so. Originally, everything in C was basically a 16-bit int. Structs were just a set of offsets. There was no type-checking; any struct field could be used with any pointer. Then came K&R C, which added a type system but made the syntax context-dependent, because the original language hadn't contemplated user-defined types. ANSI C made the type system consistent. C++ added objects. ISO C++ added templates, collections, and lots of other stuff. Now the language and its manuals are huge.
LISP also went through this cycle, again taking about 20-25 years to go from LISP 1.5 to Common LISP. So did FORTRAN and BASIC. Perl is now well along into this cycle.
If you put in the type system first, as Java, Python, Pascal, Ada, and Smalltalk did, the end result is cleaner, but the language gets an initial reputation of being complicated. Perl, though, has now grown to be more complex than any of those languages, so it's on the downslope of the cycle.
On a funny note, it's probably so people couldn't post derogatory statements about slashcode (pre-bender) that had examples in them (I finally figured out what $S is but wtf is $I?).
On a not-so-funny note, it's not just that "junk" chars are verboten, but the lack of a 'pre' or 'code' tag with which to meaningfully render code is a real bummer. Especially in this section, a priori a code-focused one. I'd propose relaxing the restrictions on 'code' or 'pre' here but I'm sure it would be a pain to implement[1].
[1] yeah, yeah. trolls abusing it for page screwage. cry me a river, and while you're at it just set threshold = [1 .. 3]. ;-)
--
News for geeks in Austin: www.geekaustin.org
News for Geeks in Austin, TX
For those of you in Victoria, Australia, You can go see Damien Conway talk about some of the things he is doing for perl at the moment.
More details are at http://programmers.luv.asn.au/
There is a theory that if anyone ever discovers exactly what Perl is for and why it is here, it will immediately disappear and be replaced by something even more bizarrely inexplicable.
There is another theory which states that this has already happened...
There is yet a third theory which states that both the first two theories were concocted by a wily editor of the Camel Book in order to increase the universal level of uncertainty and paranoia, and so boost sales of the book.
siener's youtube channel
IMHO the two languages focus on different things. Perl vs. Python is like poetry vs. technical docs: the former has a lot of artistic freedom, and some things can be made more powerful/compact, but it is difficult to use properly, more so in larger projects. Or you could even say they are like Gimp vs. LaTeX as writing tools. Usually I prefer the latter, when I want to focus on content and not worry about formatting, but sometimes you just need that creative freedom.
--
Escher was the first MC and Giger invented the HR department.
This is so confusing. Just the sight of @_[0] to mean a scalar, the second argument to a sub, makes me feel dizzy, and the little hairs on the back of my neck stand up. Please, find Damian and Larry and wake them up somehow. Cold water, dope slap, whatever it takes!
Whew. I hate those early-morning nightmares. Both Larry Wall and Damian Conway were in this dream, wearing dark suits and Ray-Bans, and, and....
Perl proudly exists for the benifit of people who like to embrace "too many ways". It allows you to write crappy code that works while you are learning, and grow as a programmer while producing functional software. Speaking for myself, when I first jumped into writing in Perl for actual applications at my job, I found that it was only a matter of two or three weeks that my code got so much better that I cringed every time I looked at the stuff I wrote on day 1 of the project. A couple months later, I could not stand to look at the crap I had written after 3 weeks. But the point is, all of that lousy code from my days of baby-steps still worked. I could go back and clean it up if I needed to, or I could just leave that pile of spaghetti lying there, functioning perfectly, allowing me to move on to more pressing matters.
If you want your choices limited, to force you into mostly good coding habits, use Java or something.
I often think that the only reason anyone uses vi is so that they can point at people who don't use it and giggle.
There are several reasons why some folks like vi:
1. It is everywhere. Pretty much all *n[iu]x OS has it rolled in, so whether you are sitting at a Solaris box, a Linux box, an old SVR4 box, you can count on vi being available. This allows you to learn one text editor, and use it on any (non-MS) server.
2. It is fairly powerful. Once you learn it, you can do some pretty fast editing of multiple files. vi is not the only editor that supports expressions, sed, awk, etc., but it does it fairly well.
3. It feels a lot like the CLI of the more popular shells. Anybody who learns UNIX will already know a lot of what they need to know to use vi.
4. A lot of first-year college kids are taught how to use it, so it is fairly universal
All that said, there are "better" choices out there (the cheering section for emacs continues to swell), and vi is mostly used due to laziness... but then again, laziness is often considered a virtue in the CS world, is it not?
I'll refrain from getting much deeper into it than that, because nothing in the universe is more tedious that a debate about choice of text editor.
Perl is not THAT bad. But why isn't the obvious obvious ?
Because Perl was not written for doing the obvious. It was written for solving challenging problems. If you evaluate all languages according to how hard "Hello, world!" is to write, you are excluding the mort powerful features of all of them. Yes, all the $_ and \@ stuff looks, at a glance, like it is harder than it should be. The same could be said of the way C handles pointers. Some people find it hard to wrap their heads around Java's use of classes.
All I can say is, use Perl for some hard jobs, instead of just trying in out on "obvious" tasks, and check out how much time you can sometimes save, once you embrace the language. You will be a Perl zealot in no time. (After all, the biggest zealots for anything are always the converted critics.)
Information wants to be anthropomorphized.
Perl is an interpreted language that lets you quickly hack big jobs with small effort.
C++ is a compiled, object-based language, designed for projects that require the advantages of the OO model and the speed of pre-compiled binary code.
A good all-purpose programmer should learn both. Asking which is better is like asking if a Mack truck is better than a Lotus Esprit Turbo... the answer depends largely on what you want to do with it.
Information wants to be anthropomorphized.
To program Perl as if it was Perl is much harder and I've yet to master it after two years of using it, but I did learn to produce useful programs in it in an afternoon.
TWW
"Encyclopedia" is to "Wikipedia" what "Library" is to "Some people at a bus stop"
TWW
"Encyclopedia" is to "Wikipedia" what "Library" is to "Some people at a bus stop"
which is why we have use strict. it makes a lot of strange "what the hell is my variable doing?!?!" type problems go away instantly. and, as with everything else in perl, you don't have to use it if you don't want to.
The example looks fine to me, perhaps you're confusing your inability to understand the language with whether or not its a good programming language.
If you like C++ or BASIC then use them instead, I really believe people should choose the language that fits their way of thinking, I enjoy using perl and find it makes sense, you may prefer C++ - that doesnt make either of them better or worse than the other.
no sig.
First point I must make, I love Perl. Its far and away my weapon of choice for most programming tasks.
Perl isn't everybody's cup of tea. There are elements of syntax that can be somewhat oblique. There are aspects that are positively obscure compared to C or Java. However, there are some fantastic points about it too. First and foremost, learning Perl is a distinctly easier task than C, Java or any other higher level language. Simple tasks in C are very simple, but anything beyond the basics is extremely taxing for the beginner. Once you're into Perls way of working you're sorted. Perl also has a tendancy to be shown as a block of regexp code too. This doesn't help.
You mention that the example 'won't even bloody compile', inferring you're used to some other compiled langauge. This is another failing of Perl. Its syntacically(sp?) really quite different to everything else. Coming to Perl from another language is difficult, more so than Pascal to C for example.
In the end, live and let live. If you can't get on with Perl then don't. There are many other options open to you.
http://twitter.com/onion2k
First of all, I really wish they'd put in a println function, I really hate typing "\n"
but then again
sub println{ print "$_[0]\n";}
print "hello";
in other thoughts, the 'is' in
%node{VALUE} = $val is Found(0);
kinda scares me because it reminds me of applescript. I dont remember applescript, but I've done some sizeable things in it, and its so close to a natural language that you get confused and start programming in english. Its good that spoken language and programming languages look so different, otherwise I'd accidentally start speaking in code.
Sneakemail is to spam filters what an ounce of prevention is to a pound of cure.
In cases like this, I use STDERR for my prompting, because
This is where someone should tell me it's OK, because there's Another Way To Do It where prompts binds STDERR instead.
[100% ISO 646 Compliant]
SVM, ERGO MONSTRO.
A common misconception:"Perl is easy to learn"
No, not really. It is not an easy to learn language for C programmers or new programmers. For C programmers there is a conceptual barrier that they need to pass to get the feel of the scripting languages.
The power of perl comes from that; ones you master perl, it is easy (and fun) to write programs.
I aggree that the perl documentation is not completely newbie friendly, and it probably shouldn't. It is one of the most useful language documentation by the way. It helped me a lot, especially the Perl FAQ's.
There are books like "Learning Perl" for learning perl. If you try to learn perl from the book "Programming Perl", which is a language reference, you obviously hit a stone wall at fifth page or so.
I think he is saying that your while statement uses an undeclared varible.
br. It should declare wha t$ticket_sold is and then do the while loop.
The Lottery:
"Not my manner of thinking but the manner of thinking of others has been the source of my unhappiness." - M
my head($brain_cells) are hurting = (newSyntax);
butMust -> learntodoit() or die "Knowing I have failed.\n";
Well, this isn't exactly the same, since it returns a new collection without mutating the old one, but in Dolphin Smalltalk one could do:
foo collect: [:x | (x beginsWith: 'comment') ifTrue: ['! ' , x] ifFalse: [x]].
so I'd have to answer 1, about 20 seconds, and yes. It's pretty easy in Common Lisp too.
I don't think Dolphin has a regex class built in, but I'd be surprised if such weren't readily available for Smalltalk - there are some pretty sizeable code archives out there. And perhaps some of the bigger implementations do have them built in.
I was thinking about it some more, and it's not to hard to do in an ML either (and at least some of these do have regexes included - SML does, and OCaml does too):
map (fn x => if String.isPrefix "comment" x then concat ["! ", x] else x) foo;
I'm not so familiar with the ML regexes, but I suspect it's merely a matter (instead of the String.isPrefix "comment" x part) doing something along the lines of (ML pseudocode follows :-)
Regex.match (Regex.regex "^[0-9][A-Z][A-Z] etc.") x. I don't know offhand what the exact syntax would be, though. Not as compact as Perl, to be sure, but certainly nothing difficult.
Perl4 to Perl5 was a real improvement. I had hopes that Perl6 might fix many of the idiosyncracies in Perl5. But it seems to add more junk to the language without helping much. $*ARGS is chomped? $ARGS prompts("Search?");? That isn't the kind of functionality that is complex enough to warrant new, oddball language constructs, and Perl5 has perfectly good constructs for those cases. And in addition to that, Perl6 also introduces lots of subtle incompatibilities with Perl5. As far as I'm concerned, Perl6 is shaping up to be the worst of both worlds: incompatibility and mess. Thanks for the heads-up: as a long-time Perl user, this really convinces me that it's time to switch.
At least that's been my experience.
--
"Fuck your mama."
The real strength of Perl lay not in its technical construct, or its syntax, or even in the vast set of modules and libraries available to it. The truest strength of Perl is its culture. Larry Wall, from very early on, has tried to foster a real, positive community.
Perl6 is yet another cultural extension to Perl5. The RFC process was very messy, disorganized, and perhaps a little out-of-control. Indeed, as Larry said, he spent several months mentally thrashing as he tried to grok all of the RFC's. But that is the way he wanted it. The RFC process was a picture of a real-life war-room or think-tank.
The end result will be very exciting, I believe. The Perl6 documents, to date, have capitalized on cultural strengths of the Perl community.
Truly, Perl6 is built on the most important resource available to Larry: the huge diversity of Perl programmers all over the world. That diversity has made Perl5 a great, legendary language. I think it will make Perl6 even better. As Perl advocates, I think our best effort is in being inclusive, rather than exclusive, in our thinking.