We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

Perl 6: what can you do today?

00:00

Formal Metadata

Title
Perl 6: what can you do today?
Subtitle
State of the Butterfly
Title of Series
Number of Parts
199
Author
License
CC Attribution 2.0 Belgium:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal purpose as long as the work is attributed to the author in the manner specified by the author or licensor.
Identifiers
Publisher
Release Date
Language

Content Metadata

Subject Area
Genre
Abstract
In this session, we'll answer "how far along is Perl 6" by exploring the things you can do with Perl 6 today. Along the way we'll discover a powerful way to parse, composable concurrent programming, a rich and extensible object system, and much more
65
Thumbnail
1:05:10
77
Thumbnail
22:24
78
Thumbnail
26:32
90
115
Thumbnail
41:20
139
Thumbnail
25:17
147
150
Thumbnail
26:18
154
158
161
Thumbnail
51:47
164
Thumbnail
17:38
168
Thumbnail
24:34
176
194
Thumbnail
32:39
195
Thumbnail
34:28
Goodness of fitProgramming languageReal numberTemplate (C++)DigitizingState observerBuildingEndliche ModelltheorieString (computer science)Formal grammarNumberGravitationClient (computing)CASE <Informatik>Event horizonSocial classPhysical systemMereologySquare numberEquals signProjective planeBitMultiplication signRight angleGraph coloringCodeComputer fileDebuggerLine (geometry)Level (video gaming)VarianceSheaf (mathematics)Task (computing)Maxima and minimaDivisorDescriptive statisticsMemory managementMatching (graph theory)File archiverDependent and independent variablesSpacetimeState of matterLatent heatData structureQuicksortAuthorizationRadiusInformationKeyboard shortcutSoftware testingMotion captureMassRegulärer Ausdruck <Textverarbeitung>Key (cryptography)MetadataAverageCoefficient of determinationObject-oriented programmingParsing1 (number)Poisson-KlammerOperator (mathematics)ParsingArithmetic meanImplementationSet (mathematics)WordComputer animation
Matching (graph theory)Game controllerAlgebraic closureCodeProduct (business)Formal grammarRule of inferenceDebuggerMacro (computer science)RadiusClosed setBlock (periodic table)Pole (complex analysis)
Line (geometry)Staff (military)Moment (mathematics)Matching (graph theory)BitCodeSpacetimeFormal grammarQuicksortNumberWordKey (cryptography)Source code
SpacetimeWeightSocial classWhiteboardNetwork topologyState observerData structureMultiplication signDebuggerFunction (mathematics)FreewareSource codeXML
Loop (music)Data structureOperator (mathematics)InfinityElectric generatorInformationFormal grammarNetwork topologyState observerRule of inferenceWorkstation <Musikinstrument>Maxima and minimaComputer fileAreaArithmetic meanPoisson-KlammerEndliche ModelltheorieProgramming languageXML
Operator (mathematics)Right angleNegative numberSystem callElectronic mailing listFactory (trading post)RewritingReduction of orderCASE <Informatik>VotingSequelArithmetic meanLecture/Conference
LinearizationMereologyMessage passingCylinder (geometry)String (computer science)Type theorySystem callWorkstation <Musikinstrument>Instance (computer science)MappingQuicksortBitCodeHash functionSocial classPairwise comparisonArray data structureFormal grammarAttribute grammarData structureComputer fileGroup actionNetwork topologyMoment (mathematics)Electronic mailing listDebuggerStreaming mediaMathematicsComputer-assisted translationRadiusPolarization (waves)Multiplication signGraph coloringExtension (kinesiology)Residual (numerical analysis)Basis <Mathematik>Graph (mathematics)EstimatorXMLJSONUML
Quantum stateGroup actionPoint (geometry)Category of beingData structureCodeObject (grammar)Radical (chemistry)Rule of inferenceFormal grammarNumberWordMatching (graph theory)Single-precision floating-point formatDebuggerComputer programmingMultiplication signInteger1 (number)SummierbarkeitEvent horizonBitState of matterSubject indexingSystem callVariable (mathematics)Reduction of orderNetwork topologySocial classClosed setDecimalStatement (computer science)Message passingDivisorToken ringPoisson-KlammerInterior (topology)
Object (grammar)Moment (mathematics)Level (video gaming)Key (cryptography)String (computer science)Matching (graph theory)Group actionConstructor (object-oriented programming)Token ringSet (mathematics)BitMehrplatzsystemAreaNumberState observerPattern languageComputer animation
BitAbsolute valueMobile appAtomic number
Default (computer science)State observerQuantificationConstructor (object-oriented programming)Keyboard shortcutElectronic signatureGraph (mathematics)Workstation <Musikinstrument>Line (geometry)Level (video gaming)Social classNumberParameter (computer programming)Arithmetic meanInformationElectronic mailing listVariable (mathematics)Key (cryptography)Hash functionDeclarative programmingComputer fileFreewareData structureObject (grammar)Attribute grammarGroup actionReading (process)Product (business)Medical imagingShape (magazine)QuicksortDisk read-and-write headXML
Endliche ModelltheorieObject (grammar)Workstation <Musikinstrument>Group actionSet (mathematics)Array data structureParsingSocial classNumeral (linguistics)RobotGraph (mathematics)Electronic mailing listDemo (music)Line (geometry)NumberElement (mathematics)Greatest elementTotal S.A.Graph (mathematics)Level (video gaming)CodeCellular automatonPosition operatorContext awarenessDisk read-and-write headSource code
File viewerBackupCASE <Informatik>Library (computing)Virtual machineBitDemo (music)Arithmetic meanDefault (computer science)Graph (mathematics)View (database)TheorySource code
Workstation <Musikinstrument>Inheritance (object-oriented programming)CASE <Informatik>Graph (mathematics)Electronic mailing listSet (mathematics)Structural loadSystem callHash functionDrop (liquid)10 (number)Mechanism designArithmetic meanDot productSocial classMeasurementProgramming languageMereologyAsynchronous Transfer ModeState of matterCategory of beingForm (programming)Source codeXML
Multiplication signAverageHash functionBitCodeMeta elementEndliche ModelltheorieComputer programmingOrder (biology)Graph (mathematics)QuicksortPresentation of a groupSpeicherbereinigungVirtual machineSet (mathematics)Electronic mailing listMeasurementNumberLine (geometry)Maxima and minimaDivisorPower (physics)Attribute grammarSound effectConstructor (object-oriented programming)Arithmetic meanRun time (program lifecycle phase)Java appletObject (grammar)Workstation <Musikinstrument>Semiconductor memoryResource allocationField extensionPattern languageLattice (order)Pulse (signal processing)Video gameProcess (computing)Communications protocolSoftware testingPlotterSingle-precision floating-point formatDiffuser (automotive)MetamodellParallel computingImplementationLevel (video gaming)Operator (mathematics)VariancePhysical law
1 (number)Endliche ModelltheorieGroup actionMultiplication signCompilerJust-in-Time-CompilerMassComputer programmingCodeProcess (computing)Closed setPulse (signal processing)Electronic mailing listRight angleTable (information)Goodness of fitStudent's t-testSoftware testingMechanism designNetwork topologyProgramming languageThread (computing)Parallel portJava appletMultiplicationWritingCore dumpConcurrency (computer science)Directory serviceVirtual machineSet (mathematics)Computer animation
Block (periodic table)Prime numberCore dumpCodeBitPoint (geometry)ResultantNumberElectronic mailing list
Electronic mailing listCodePulse (signal processing)Directory serviceDifferent (Kate Ryan album)Staff (military)Strategy gameCASE <Informatik>6 (number)QuicksortMetropolitan area networkBuildingLevel (video gaming)Table (information)Loop (music)Scripting languageResultantPoint (geometry)Process (computing)Mathematical optimizationComputer programmingControl flowProduct (business)Asynchronous Transfer ModeReading (process)Drop (liquid)Network topologyMultiplication signSoftware testingProjective planeParallel portDialectOcean currentShape (magazine)State of matterPower (physics)Virtual machineModule (mathematics)Moment (mathematics)Human migrationCompilerPrototypeFront and back endsArrow of timeVoxelObject-oriented programmingSemiconductor memoryProgramming languageRange (statistics)Formal grammarInsertion lossSystem callSuite (music)Arithmetic progressionQuality of serviceRight angleProteinSpectrum (functional analysis)Concurrency (computer science)1 (number)WritingParallel computingGraph (mathematics)ParsingBitQuadrilateralCore dumpLatent heatObject (grammar)Multi-core processorTask (computing)Goodness of fitBlock (periodic table)Structural loadCuboidSpacetimeTerm (mathematics)Software bugHookingHypercubeOrder (biology)Graph (mathematics)Computer animation
Lecture/ConferenceXMLUML
Transcript: English(auto-generated)
So, good afternoon. It's very nice to be here to make it to positive at last. And thank you very much to Benmore Infrastructure for some of them.
So, for example, we have a lot more syntax and things related to, say, object orientation. It's gradually quite, and that is quite a surprise,
build your way up from something very small into something very big
and refactoring as you go along is something that just feels very natural. So I have to say, of all the languages I've worked with, I find evolving my Perl 6 code to be one of the easiest languages to do an evolution. So, the specification of the language is actually a test suite,
meaning that in my time we're very open to multiple implementations. There's a standard grammar, which is actually written in Perl 6 as well. And there's a great community around this, part of the joy of being involved with a decidedly long and sometimes quite tiring and challenging project. There's a lot of really great people involved in this as well.
So, that's a basic little look at what sort of language we're talking about, what sort of project we're talking about. What I sort of want to do today, and that means we're actually going to build the compiler,
how it actually feels to be a user of the language. And I think it's really important to do that from time to time. So, we try and dog food a few things. For example, the debugger for Rakuto Perl 6 is actually written in Perl 6. So, we've actually been building a lot of the pieces that we need
to build the language in the language itself. And in the last year, I actually used Perl 6 over at a real-world client. It was, to be honest, a case where they didn't really care what I used, they just cared about getting results. I used Perl 6 to basically throw away half a million lines of their code base
without them noticing, apart from the build process. Well, I was kind of thinking, what can I do with Perl 6 that we can fit in an hour
and that sort of lets us explore the language in some kind of interesting way. And for various reasons, I've been looking for various big data sets or interesting data sets that you can find around the web. And one of the curious ones I came across was a huge archive
of historical global temperature data. And I was like, oh, that sounds interesting. And of course, it's not in JSON or XML, it's just in this big heap of junk, which is going to be a little bit of fun to try and get the data out of. And what I wanted to do is just explore it a little bit. I ain't got any agenda here or anything like that.
It was just a sort of typical data munching task, and I thought, yeah, okay, let's see how we can do. So this is the kind of thing that you get, okay? Does anyone know where Yanlian is? It's an island. It's an island, yep, about where?
Norway. Yes, it's a Norwegian island. It's actually a very, very long way from Norway. It's in the middle of the Atlantic. It is actually reckoned to be the place on Earth that's inhabited with about the least sunshine, because it's basically cloudy all the time and cold.
So it hasn't done very well as a tourist destination. In fact, it basically is a military island with about 18 people there year-round. So, you know, I haven't been there or anything. But anyway, it's pretty cold, it seems. These are the average temperatures for each month of the year. And, yeah, it's a little bit chilly.
The highest that you get is 7.2. And that's in a hot gear, it seems. Basically, you get this data here, and it's a bunch of metadata at the top and a bunch of observations. So you kind of look at this and you're like, okay, let's try and actually pull the information out of here. Alrighty, so how do we do that? Well, I've always been very good at grabbing stuff out of text.
The only problem is that by the end of doing a lot of this, a lot of the time the code devolves into this huge mass of regexes that are really quite a bit of a pain to actually maintain. And recognizing this, in Perl 6,
we actually put full support for grammars into the language. So instead of having to try and then move on to other parsing technologies, you can take your knowledge of regexes and then basically just extend it a little bit and be able to parse much more sophisticated languages. And this gives us a much better structured way of doing this.
They're composable, so you can be parsing one language and then say, oh, we're in the middle of a bunch of, say, templating language, but here's a bit of SQL. Let's switch to a SQL parser for a while. Okay, we're done. Let's switch back. And that was very extensible. You can actually subclass these parsers. And they're fairly easy to maintain as well. So let's take a little look at how we build such a thing.
So we use the grammar keyword to introduce a grammar. And we give it a name. And what we're going to do is the hat and the dollar, you can probably guess. Okay, start of string, end of string.
That's perfectly familiar. And then we have the plus there. That's the plus quantifier that you know from regexes for saying one or more. But what we do is instead of just going off and writing all the stuff to match, we basically call two other bits of regex. And what I'm doing is I'm describing the sort of overall structure of this.
So I'm saying there's one or more key values at the top. Things like number is this, name is this. And then there's a bunch of observations, this section. So, what now? Well, let's do a key and a value. So what I'd like to do is not just pass this but have a way of actually pulling all the information out of that.
So what I'll do is I'll bind to a named capture. That's what that bit of syntax is over there. So the key is going to be, and we'll just match a bunch of word characters. Okay, that's sw+. Square brackets are not character class, they're just grouping. Now what I then do is I'll match an equal sign.
You can just put quotes around stuff to match it literally. We then will match some horizontal whitespace. Okay, and then anything that's not a new line, that gets us the value. Okay, so fine. That basically is going to let us pass the keys and values. Now, what next? Observations.
That's the text ops. Potentially some whitespace. The files are not entirely very consistent. And then at least one observation. And an observation. What's an observation? Well, it's a year. That's a bunch of digits. Some whitespace. And this is cute.
This is one or more temperatures. And this modulo thing here means separated by. Okay, so it takes the previous quantifier, the plus, and it says between them there should be this. Okay, so basically a bunch of numbers separated by whitespace. Alright? And then, what's a temperature?
It's maybe negative. It's a digit, a dot, and some more digits. And that's it. That is a complete description of how to pass this text. And it's nicely broken up into small pieces. So we can understand what each of the little bits does. So, the question is, will it work?
Well, let's see. 6M. Ooh, ooh, ooh. Ooh, nope. Thank you. Failed match. And the trouble with this, of course, is you're like,
why didn't it work? And, you know. When grammars don't work, you're kind of like this. And then you're like, well, what should we do? I mean, one of the nice things you can do is you can actually just go and write any closure you like inside of one of these production rules. And it works very nicely.
And we can just go and do say and just pull out those two things that we match. And we could do that, but seriously, use the debugger. So, the debugger is much, much nicer for this. The debugger is actually built in Perl 6 for Perl 6. It knows about debugging all of the weird stuff.
Big in blocks, code that you eval. You can step into macros, regexes, and, yes, grammars. OK. So my thing didn't work. So I want to debug it. So instead of saying Perl 6 and that, we'll just put in debug. OK.
And let's have a look. OK. So what it does is it sort of brings me into here. And it sort of highlights this line of code. And when I hit that, it actually takes me into my grammar. And you can sort of see the yellow there.
And it also has the bit of text that we're matching. And as I go through this, OK, we call key val, we call the key, we look for the backslash w plus, OK, and see number one green, because we passed it. OK. Now, that's fine. And what I'll do is I'm just going to keep going through this, OK? So you can say om nom nom nom nom.
OK. As we go. And this is looking OK. Did you see what happened? You see that we got the word start, but not year. OK.
What we did is we passed with backslash w plus to get the start. But then we weren't matching whitespace for the keys. OK. So we missed out passing the year. Dope. OK. So, well, that was a silly mistake.
Let's fix it. OK. So here it is. And that's not the right size for you to see it. There it is. OK. And here, what am I going to do? I'm actually just going to say, well, it can be, let's do a character class, whitespace as well. OK.
And I think that this will fix it for us. So let's try it. And I'm not going to do it under the debugger this time. We'll just go straight for it. And, whoa, that's a lot of output. But you can see that it actually seems to pass the thing. And down here, what we're seeing is we have an observation.
OK. And then we have the year. And we have all of the temperatures have been pulled out. And it's actually gone and captured all of the structure of the data as well. So basically, you get the tree for free.
OK. You don't have to go and build up your own data structure if you want to start working with this information. So let's do something really simple, just straight off on that tree. So we pass this file, OK, with the grammar. And then what I'm going to do is I'm going to look for the lowest and highest temperature
that we ever observed in all of these observations at this weather station. So I start out looking at my lowest one and highest one, OK, and we just put infinity and minus infinity in there. And what I'm going to do is a for loop, and you can remember the structure of the grammar. At the top, we look for observations. And the observations rule can match a bunch of observation.
And it was quantified with plus, so we get an array. And I can loop over each of these, OK. That's just naming the variable that we're going to shove the thing we're iterating on into. And then all I need to do here is loop over the temperatures, OK, of that observation.
And then here, you know how you can save things like plus equals or minus equals or multiply equals? There's a min operator and a max operator. They're the infix. So you say this thing, min, this, and you get back the smallest one. Well, you can do min equals and max equals. These are actually not really hard coded into the language.
They're generated. So if you introduce your own new infix operator, you get this for free, OK. So with that, we can just quickly go through and find the lowest, the highest, say them down here at the end. OK, so that works. And that wasn't too hard.
So why would you say, why is it the lowest min equals something? Why don't you just say lowest equals min brackets? I mean, that would be an old-style syntax. Is that better? Am I understanding correctly? Well, the operator itself.
Let's pull up our apple. OK, the operator itself, if I say one, ah, 21 will do, min 42. I get that. Which is 21. And the thing is that if all of these operators, you know how you have plus,
you get to write plus equals instead. And if you want to do something like a plus equals one, well, you do a plus plus, well, two, like that. And the min one is just the same case. I mean, we know that that rewrites to a is a plus two.
And so a min equals b rewrites to a equals a min b. OK, it's just completely productive. It's not that none of these operators, we call them meta operators. The things like the equals and negation, because they take existing operators
and they basically just modify their behavior a little bit. And we'll see a few more of those. And they're completely regular. If you define your own new operator, you get them all for free. So I guess what I was going to understand there is min is just between two values rather than operating on a list.
Correct. However, if you have a list, you can do a reduction. OK, that's reduce. And that's completely regular as well. For example, that's how you ask if the whole list is numerically equal.
OK, you can do it with all of them. OK, that's ten factorial. OK, yeah. So, yeah, they're even useful.
OK, yes, go away. OK, so, ready. Do you use a pass-on method? What if I want to pass a linear in, for example? We have a cylinder and we don't have a pass.
Yeah, there's a pass method which just takes a string. No, not a string. Oh, you want to do it with a stream. That would be done with cat. We don't do lazy stuff on them yet. OK. It's one of those, in the future, we will do stream passing but not now.
So, and generally, unless you've got something insanely big, it's not a problem. But, yeah, you'd slurp it in. If it was some of a file handle, I'd just grammar.pass $file.slurp, OK? And there we go.
And you don't have something for the progressive scan, like an equivalent to sex? No, it is not a progressive thing. Not at the moment. Yeah, question there. With the min equals and max equals, why do you have the unary plus in front of the T variable? Oh, why do I have that there? That's a really good question. Min and max will do something based on whatever kind of type you have.
So if you have a, min, b in their strings, OK, then you'll get string comparison. Because this is passing the grammar, everything that comes out of it is a string, OK? It's all text. Plus is how you nullify.
And it's smart. If you do plus and the string is 42, you get an int. If you do plus and the string is 5.6, you get a rational lack. So it gives you the narrowest sensible type. OK. So, we pass, but there's, this is sort of OK.
But I'm not really happy yet. And the reason is that if the grammar changes or evolves with time, OK, then that structure of that tree is going to change and this is not going to be the most maintainable of solutions. So if I want to sort of make this a little bit more maintainable,
or just actually get a lot neater code out of this, rather than digging into hashes and arrays and so on, I'd really like to turn this into some kind of more interesting data structure. And what I'd actually like to do here is to actually create myself a little class. I'll call it StationData.
It represents the temperature data from a station with a certain name in a certain country and there is the array of data. And what we're going to do for the array of data is it's going to be a pair, OK, that takes a year and maps it to the list of 12 temperatures that we got observed that year.
That's what data is going to be, an array of pairs. Now, all attributes are actually private and really named dollar exclamation mark foo. So dollar and at and percent are all about essentially the structural type that you have.
So if you put something like at x, OK, that's going to be an array, that's going to flatten in list context, just like you're used to it doing in Perl 5. And dollar is always an item and it is not. But we have introduced these, we call them twiggles, secondary sigils, which tell you something about the scope of a variable being unusual.
And the exclamation mark one simply means this is private to the class. Now, when you write dollar dot name, it actually declares you a private thing and then it makes you an accessor method, OK? So your cost of private or public is whether you type dot or exclamation mark.
So now that we have that, we need to actually build up instances of this class. And we're going to do some interesting stuff in there in a little bit. But the first thing that I need to do is actually find a way to take my grammar
and the stuff that it's producing and actually grab out the interesting data and build up this class. Now, to do it, we write something called actions. And rather than just go through the code, what I actually want to do is take you into the debugger. It turns out the debugger has a REPL mode, OK?
So this can be really nice for understanding what another bit of code does, because if I say for 1 to 5, OK, dollar X, and then we say dollar X, OK, and we just try this, then what we'll find is that we can now single-step through it, OK?
And we can even just look at the variables as well, OK, or do exactly what we want. And if I just hit run, then that runs to the end. And now I've got a chance to do some more code. And of course, that returned me a bunch of Booleans, because, say, we'll do that. OK, fine. So let me just do this again but show you grammars and actions.
So let's try the grammar, a really, really simple one. And I'm going to have a top token. And what we're going to do is something really nice and straightforward. We're just going to match one or more integers separated by commas, OK?
And then token int, that's going to be some integer. OK, so a really, really boring little grammar rule there. OK, so it comes back and it tells me that I declared a grammar called G. OK, so the G in brackets is there. So, what I can do is I can write a class A,
and I can give it methods with the same name that take a match object. Now, we have a special variable, dollar slash. We don't have a lot of special variables in Perl 6. We have like three of them now, which is quite a good reduction. And yeah, dollar slash is the match one.
And actually, it turns out that if you write dollar zero or dollar one to get at the things you captured in a regex, that is now actually just syntax for indexing into that thing, OK? And if you want to get at named ones, of course you can do, well, you could do that, OK?
But we can write that now as that. But if it's into dollar slash, then actually you can write it just as that, OK? And pull the value straight out. So we made it very convenient for you to work with these things
that come out of grammars. Now, if I actually just in here, let's put some bogus statement in, OK? And then in here, we write a method int, the same, OK? And again, I'm just going to shove some bogus statement in, and we'll single-step this. So what I'm going to do is g.pass, OK?
And then I'm going to pass in one comma two, OK? And I'm going to say use the actions class a. And at the end of this, we'll see what this does. So we're going to start passing, and we go looking for an int, OK?
And we look for the number. And as soon as we've matched it, we find ourselves inside of this action method. So it's a callback, OK? Every time you hit something, you get this callback, and you get to run some code. So I can actually look at what we captured, OK?
By looking at dollar slash, and it tells me it's a match, OK? One property we have on there, you might see, is this AST one. And what this lets me do is associate some other object with this match. And I can do that just by writing make. And what I'm going to do is take that match object
and just do plus dollar slash, that is, make it a number, OK? Turn the text we matched into a number. And this is one of the cute things about the debugger. You can actually just eval arbitrary code at any point you want in your program, OK? To tweak your program state. So you can tweak variables as you debug, if that helps you find your problem.
So I'm going to just do make on that, OK? And if I look at this again, that one has now been stashed under this AST property. Now, you might wonder why this is useful. And let me just go and we match the comma, we match backstd again, OK? And I'm just going to again eval make plus dollar slash, OK?
And what we should now find is that we end up in the action method for top, at which point we can retrieve, we can look at int 0, OK?
That was the thing that we matched. Let me stringify it for you just so you can, oops, we should put a P on there, OK. And the other one that we matched was that. But that actually is, if I say what is it, oops, not that, take that off, OK.
That's a match object. But if I want to grab out that number that I left behind, OK, there's the 2. What is it? OK, it's an int. So it's the thing we stored. So basically we can pass things up the tree, OK, and construct whatever data structure we want out of them. So what I'm going to do in my, if we go back to this,
is I have an action method written for all of my various tokens that I'm interested in. And let's start with key val because it's easy. We take the key, that turns it into a string. We take the val and we turn that into a string and then we make a pair.
And in Perl 6, that pair constructor actually makes a pair object. Pairs are not just fat commas in 6. That actually is a pair object there. And we just pass it on up. What about observations? Well first, a single year's observation, we make a pair.
And then what we do is we take the set of temperatures and all I want to do is match them into numbers, OK. So at the moment they're match objects that represent the bit of text we captured and the offsets and so on. And all I'm doing is I'm doing a map. We can call map as a method.
And that's star dot num. It's also worth just a moment's explanation so let me do so. So you know that we could actually write something like 2 star dollar underscore, OK. And then I can call a with 21, OK, and we get the answer.
But it turns out that there's actually a, I put an extra star there, OK. That also, and of course we could have done 2 plus that, OK. And you can actually have one that star dot abs, OK.
Which is just going to call the abs method, absolute, on anything I pass in. So if I just do minus 5, then I get 5 out, OK. And this is a very, very neat bit of syntax. So we do that there. And a level of, OK, what I do is I take all of the observations.
Remember observation was plus, it's quantified. So it's a plus quantifier so we have lots of them. And what I do is I map them and I get the ast. And then, I didn't used to have this graph on the end. And then I found something really, really horrible.
It turns out that a bunch of the data files indicate missing data by having a temperature of minus 99. Which I guess will never actually happen on Earth. So, at least not in the real world. But we need to filter them out. So all I've done here is I've just said, OK, that made a pair, OK. So dot value is getting the value of the pair, which is the list of numbers.
And I'm saying none of them should be less than or equal to minus 99. So it kind of does what it reads like. Values, none of them are less than or equal to minus 99. So, finally, at the top, we pull it all together.
We take the station data class we call new. We get the default constructor for free. And what I'm going to do is I'm just going to pass in the info. Then all I'm doing here is taking the list of key values, OK, and doing dot hash, which turns them into a hash.
So that's a way of turning a list of pairs into a hash. And then the observations, we just grab whatever we made here, which is the year pointing to the bunch of numbers. And then we have a station data object. Well, almost. You see, what we actually want in the station data object is the country.
And the station name, and then the data. And the data is in pretty good shape, but the rest kind of isn't. So what we do is we write a build sub-method. This is a non-inheritive method, and you use them for infrastructural things. And build gets called with the named parameters passed to the constructor.
And what we do with it is what we do is we take them as named parameters. That's the signature syntax for named parameter. OK, you put a colon before it. And here, all I'm doing is I'm binding to name. I'm just looking the name up, and the country up.
OK, and then data. Now, that's fine, and that works. And it's perfectly acceptable Perl 6 code. However, I'm lazy, so let's do a couple of shorter names of this. The first thing is that you can actually just bind a parameter directly to an object attribute instead of binding it to a normal variable.
So if I do that, then that line goes away, and that just goes in there, and we bind it straight into here. The other thing is that you can actually do data structure unpacking as well, meaning that I can take info, the hash, and I can then write another signature which takes the hash,
pulls out the name, and shows it into the name attribute, and pulls out the country, and shows it into the country attribute, and that star percent there means, and ignore all the rest of the values that are in the hash. OK, so basically we've done the whole thing with declarative programming there, rather than actually having to write anything.
So, not bad already. So, if we want to use the actions, OK, we can do so. We can just go and save the file, and we pass actions, and then a get.ast at the end.
And if we run this one, let's do that, OK. And I think, was it 02? No. OK, 03. No, it was 04. Model actions. OK. And if I do this, then, whoop, there's a load of data. And you can see what this data is, perhaps.
And let me just scroll way up here. OK, and you can see it's a StationData object whose name is Jan Mayen. The country is Norway. It's Norway, actually. And here we have the array, so in 1921, these are the 12 temperatures. OK, in 1922, these 12, and so on.
OK, so, it works. So, so far, we have a grand total of 36 lines of code. OK, we have a nice parser. We have a basic model class. And we have an action methods class just to play with.
So what I'd like to do is to plot myself a little graph of the future each year over the different years that we have data for the station.
OK, so let's do a graph. So the first thing that I want to do is write myself a method, yearMeans. And what we'll do in this method is we'll take, remember the thing I showed you with plus? OK, which adds a bunch of numbers together. And we'll just take that plus and we'll add together all the values and then we'll use an array in numeric context, just like in Perl 5, it's the number of elements.
OK, so that's the mean. So, now we have the data. And we'll map it. And if you remember, it's a set of pairs.
It's pairs of year.
It's also called as a group, it's more than CPAN. But we're gradually building.
Remember, that was a list of pairs from year to mean number. And you can actually plot multiple lines. This here is the year, OK, to go along the bottom of the graph. And here, because you can do multiple data sets, I just have to wrap that up in a couple of pairs of arrays because we can actually give multiple lines
and we'll do some more different lines on two graphs on the same graph later on. We then take the name of the station and we say bot xyLines. And what happens if we run this? Do I dare demo this one? Let's see. Yearly means, OK. And if we do this...
No, I don't dare do this one. I need to tell it where to find the libraries. OK, and if we do that, then what should come out? Oh, and here's the really embarrassing bit. You will not believe what the default viewer for SVG is on this machine.
Yeah. But look, it's a graph of means. So, it works. That was my backup in case the light demo went horribly wrong. And I don't know what happened in the late 60s, but apparently it was pretty chilly. Does anyone actually know? Was it a remarkably cold winter? Yeah? OK.
I wasn't there, so... Yeah, really. Anyway, there's the mean temperatures over at Yan Mine. So, interesting enough. Alrighty, so what next? Oh, that was not what I wanted.
That was what I... No, that was what I wanted. OK. So, the thing is that I haven't just got data for individual stations. I've got loads and loads of them. Tens of thousands. And what I want to do is just actually start looking at doing this by country. So, we can actually plot a graph of the mean measurements across all the countries.
Now, we start out just by doing this. We find a country, we can actually name a set of stations.
Actually, having data for one station is just a special case of having it for lots of stations.
So, somehow, we should hopefully be able to factor it like this. So, what I'm going to do is I'm going to introduce a data sets method. And for stations, it just wraps the data up in an array and returns it. OK, that is an array ref.
So, that will not flatten. And now, what I can do for my other one is I can introduce a data sets property. And all we're going to do in here is we're just going to map the stations into their data and do dot item on it to stop it all splurting out into one big one list. OK, I want to keep a list of them.
So, we have the data set for each station. So, now I have a way of just asking for the data sets that is the station's data that I want to compute the mean on. So, the question is where or where should I actually write the method to do that? And one, you know, question you might have is, well, maybe a common base class.
OK, but no. That's not really what common base classes are for. Inheritance is really a mechanism for specializing behavior. And classes are really about responsibility. So, call six, the thing that we provide you with for compute.
So, what I can do is I can write a piece of the hash and a list of the temperatures that you have here.
And then all I need to do is use the data set. So, what I think you can get to me is actually eventually, I think,
because Moose brings them very, very nicely in 12.5.
And naturally, in 12.6, we have them as well. OK. So, when I do this one, I get a graph like this. OK. This is the graph of mean temperatures of all the stations in Norway over the years.
And I looked at this and I'm like, my word, it's getting colder and colder in Norway. And, of course, the data is not actually very legit. OK. And you might wonder why it is. So, I went digging and what I realized is that there wasn't data for all the weather stations for all the years.
And the two big drops in the graph are when they basically bought new stations online. And the thing about Norway is it's really, really big north to south once you count the islands. OK. It starts below 60 degrees north. And once you get all the way up to Svalbard, you'll hit more than 80 degrees north. Norway is huge. Or at least all the islands are huge.
So, I'm not at Svalbard anymore. Anyway, basically this was skewing the data. OK. Because you started with a bunch of weather stations doing cold places and everything.
And what I did in the end was just count the truth a little idiot here. You can actually put an initializer on an attribute. And it will run after all the rest of the object construction is done. OK. If you haven't otherwise initialized this. So, I just do a do and I just go in here and I just take.
And all I'm doing here, you can see I'm getting the number of data sets. I'm going and counting how many data sets have a measurement for each of the years. And then I'm grepping out those where we counted the number of data sets for the year.
OK. And you might be able to find a cuter way to do that in 12.6. But that at least is a fairly boring way of doing it and it works. OK. So, now I could filter those out. And the graph looks a lot more sensible. OK. But we have less years worth of data. But that one sort of shows the average is prepped up a little bit towards the end there.
Which is a little bit interesting. So, OK. Finally, again, I won't go too much through the code. But what I did at the end was I wanted to calculate the high and low temperatures.
I just want to show you in this code that what I did was I factored out a way of taking a thing to do. Just looping over the data sets. OK. Skipping those that are not in a year that we have data from all the data sets for. And then I just call the thing to do and pass in the year and the temperature.
And that ampersand there is just a way of taking a piece of code. OK. It's the way that you can do the higher order programming stuff. Which is kind of nice. And then what we need to do to actually do the lows. We can run the min equals operator. OK. So, all I am doing here is I am doing year lows.
We are going through all the valid years and all the data sets. We are getting the year. We are getting the temperatures. We are finding the minimum temperature for those. That actually appears as a method on the array as well. And then I am doing min equals to get this minimum factored in to that year list there. OK.
And what I will get at the end is I need to take this hash and I need to hand the years back in order. Which means we take the hash and we sort the pairs from the hash by the key. That's the year. And we map out the values. OK. And what I actually got out of this was a graph that looks like that.
OK. For Norway. And you can see that the minimum temperature down here, the lows, actually seem to have maybe been rising a little bit. The highs haven't actually changed quite so much it seems. And that means the overall effect on the mean is kind of not that much.
It's kind of curious when you see this graph and then you realize that that blue line is actually that line there. It's just that once you put it into perspective and see it on a graph like that, it looks a little bit less scary. Which is basically presentation is everything. OK. So all of the stuff that you've seen so far.
I've actually been running it. I've actually been running Perl 6 here on a virtual machine called MoreVM. Which is short for meta model on a run time. It's basically a virtual machine built around meta-object programming. And it actually has the fastest startup times of any of the Perl 6 implementations.
So it starts faster and it generally has the lowest memory use as well. Now, it's coming on very nicely. It's not too bad. We haven't managed to crash it today. And it actually is fairly hard to do that with fairly long running stuff.
Because we did a... There's some really great work with the garbage collector basically torturing it. And making it do a garbage collection run after every single object allocation. We then ran some very big tests on it. And they ran for something like three weeks. And it hadn't actually crashed.
So then we were fairly happy that it wasn't doing too badly. So we've really been torturing the thing. Now, the other thing that you can do is run it on the Java virtual machine. Now there's some pros and cons. The pros are that it often, once it gets going, tends to be a decent bit faster.
I don't have a number comparing JVM against MoreVM. But certainly there was one guy who took his code that he was running with Perl 6 on the power virtual machine Ran it on the JVM and it ran 40 times faster. So that list can be quite a big speed up. And you might wonder how hard it is to take the Perl 6 code we've written and run it on the JVM instead.
And you might have been noticing I've been invoking it as Perl 6M. And it turns out that all I have to do in order to run it on the JVM instead Is to... let's actually just go for one of the simpler ones. Let's go for model actions.
And let's just do Perl 6J instead. Now the start of time is incredible. However... OK, finally. So once it gets going and its JIT compiler goes to work It often actually comes out and gets ahead.
By potentially quite a long way. So if you have long running stuff, this can potentially be quite a big win. Now one of the other reasons that we really wanted to be on the JVM And the fact that basically every other language is there So we should probably be as well Is that the JVM is a place where we can run code in parallel
And it's very very mature about that. It's a very normal thing to write multi-threaded code in say Java And when we wanted to get the Perl 6 concurrency features And really have a nice stable VM to build them on and test them on
And basically did this stuff in the real world already You know, very big machines And the JVM was kind of a natural place. Now what I want to show you, just to finish this session off Is to actually show you how difficult it is to take the program that we have written And you've just seen me run it on the JVM and the full thing works as well
And then we're going to actually just parallelize it We're going to make it so that it can run on multiple cores And crunch through this big data set in parallel. So, here is the code that goes over a list of directories of the data
And then goes over each subdirectory And passes it. So this is basically going through all the directories, all the subdirectories, all the files, passing them. And it's doing it sequentially.
So, let's do it in parallel. And the mechanism we're going to use We've got various ways of doing these things in Perl 6 But the mechanism we're going to use is called promises Because they're the most natural way of doing this one And I just want to show you what a promise is So here, what I'm going to do is I'm just going to call start
And I'm going to give it a block of code which basically takes the numbers from 1 to infinity And grabs them, and you'll be glad to know that's a lazy list And then we just test them for primality And I'm looking for the 5,000th prime And I'm just going to get that and shove that bit of work off on another CPU core
And I'm just going to look at the status of this promise And you'll see it turns from planned to kept So it's actually been working away on another CPU core here While I've been playing in the recall And at this point it's got a result for me And that is the 5,000th prime Well, 5,000th first if we're doing from 1, I guess
So, how hard is it then to take this and parallelize it? It's that. We only need to parallelize it so far There's no point going overboard and giving it loads and loads of individual tasks to schedule
So what I'll do is I'll actually just start in there And then what it does here is it actually does this piece of work asynchronously And it gives me back a promise representing it So what this loop does is it basically results in a list of promises For each of the top level directories and the work
And then I just say await And that just waits for all of them to be done And that's it And we can do a very similar trick for the graphs What we'll do is we'll just await Do for all the countries, start Say we wrote the graph And then we're done
So again, the only thing I've done to turn this into a parallel program Is just start there and await And of course we got lucky in this case Because the opportunity for concurrency in this program was very, very evident Now of course the question is Does this actually use all the cores? And the answer when I did this on my quad core
Hyper threaded box at home Is oh yes, it did So this is actually genuinely doing that Now of course the question is Is it actually any faster wall clock time? Because it could just be using all the cores but wasting them completely And I'm glad to say that it's a quad core machine And I got more than three times speed up on it
Just by dropping these two things in So it was actually, this is the parallel one And it's less than a third of the height of that Which on a quad core machine is pretty fast So we got a reasonable speed up
So what is the state of cross x? That's some good news I think cross x is a fairly nice expressive and powerful language You already can build some fairly interesting stuff on it Just like we've done today In the process of building this
I really did not run into much in the way of bugs I did run into warn which was actually a bug in the debug Believe it or not So I fixed that one for one of the demos But other than that This was fine And I really did just take the code that I wrote On more VM and just run it on the JVM And it all did just work
And that really is a very positive thing Because it tells us that our strategy Of using a test suite as the specification And then a formal grammar to specify the syntax And that grammar actually being in whole six as well Is actually working out as hoped It's actually letting us have multiple backends For the language, the run
Feature wise Hopefully you've got the impression from this I've been able to show you a very wide range of things We've been doing parsing with grammars We've been doing object oriented programming We've been doing higher order programming We've used lots and lots of built-ins We've pulled in modules We've done a bunch of parallel stuff at the end
And feature wise Things are in pretty decent shape Really there's a lot of things you can do today And at this point The question of a lot of things that are left in the spec That are not there yet is Well, you know, do we really need them to declare 6-0? And I think the answer for a lot of them
That we're still missing is going to be Actually, no we don't So, that's all the good stuff Of course There's a bunch of reasons why I'm not going to stand here and tell you You should now go and use Perl 6 for everything you do Ok? Because I hope at some point I can say this But right now there's a few reasons to hold back a little bit
One of the big ones at the moment is speed And in the true sense of, you know Make it work, then make it fast We've been doing the make it work And as you can see a lot of stuff does work A lot of people find that it's not fast enough for them yet It really depends what you're doing
On the JPM things are a lot better Once it gets going For scripting stuff We got startup time down a good bit There's also a good bit of memory work That we want to do as well And we've got some quite interesting stuff going on In that space right now The other big thing that is a work in progress at the moment
Is getting access to CPAM We've had various prototypes of this in the past And they were educational But in the end they didn't quite sort of get there And I'm very hopeful for the current effort Which is looking very promising And you'll find that tutorial wise things are a little bit sparse
The reference docs are not too bad But tutorial wise there's a little bit less there We really need some sort of effort on that front too But I'm fairly optimistic about things I mean on the optimization side of things It's not that we don't have a clue how to make it faster It simply is that we haven't gone and done all of those things
Actually one of my biggest priorities For the coming weeks and months Is getting a bunch of the interesting optimizations in Which is great because I get to read papers about stuff like SSA and dominance It's a technical term I'll give a talk about it sometime Okay, the other thing is that
You only get access to all the parallel stuff on the JVM So we need to get that ported elsewhere But that's actually planned for the very near future as well And I reckon that'll be there within a few months And there's actually a funded grant for doing the Perl 5 interop So that actually has funding now It has somebody who's on the hook to do it, hopefully
And we also have a project called V5 Which is very promising Which basically is using the Perl 6 compiler tools To implement Perl 5 far enough That for a bunch of simple scripts You can take your scripts in Perl 5 Make sure it still runs And then you can actually turn it block by block into Perl 6
So you can take one block and say Oh, I'm going to write this bit in Perl 6 And say use v6 and write Perl 6 code there Or you can actually have a bunch of 6 code and say use v5 And this is coming along fairly well It's being basically taken the Perl 5 spec Well, Perl 5's own test suite
To try and get this So we're thinking a lot about migration strategy as well So, if I come to fastming it next year Which would be very very nice Then here's the things that I hope to be able to tell you That we'll make things a lot faster That we'll have got memory usage down a good bunch
And that the interop actually is in place And that you don't have to choose JVM If you want to do concurrent and parallel programming Because we have that on one of the alternatives And that the documentation is better in a better place And I really do want to emphasize The community around this project is really great It's the reason I'm still doing this
And I think it's the reason a lot of people are involved, and I'm pretty sure it'll stay that way. Okay, if you want to learn more, PEL6-ORG, or drop by the IRC channel, or drop by the booth, which is downstairs somewhere. And I'm pretty sure I've used it all the time, so I will just say thank you very, very much.
If you have questions, I probably need to finish here, but do come to me afterwards or I'll hang around the booth a bit tomorrow as well. Okay, so thank you very much.