The Authentication Fairy 8
If you haven’t yet read Ovid’s post about the ‘AuthenticationFairy’, you should. Go on, you can rejoin me below the fold for discussion of some scary Perl…
Apart from offering a very powerful way of thinking about Objects and OO analysis, Ovid touches on something that niggles me about Rails1; the way ActiveRecord works.
Yes, yes, ActiveRecord’s brilliant, as an implementation of the Active Record pattern, it’s pretty exemplary.
I just don’t like the pattern. Back when I was a dedicated Perl programmer, I worked on an object persistence system which Leon Brocard named “The Magic Data Pixie” – we generally just called it Pixie – which was a very different kind of persistence tool.
Pixie’s goal was to make objects persistent. All of them. Regardless of their source. You just wrote your application, connected your objects together appropriately, then threw a ‘top level’ object to the data pixie and asked it to store the object for you and associate it with a given key.
Later, you could ask pixie to fetch the top level object you’d stored, and just carry on using it as if it’d always been resident in memory. Pixie handled proxy object, deferred fetches from the database, all the backstage stuff needed to maintain the illusion that everything was resident in memory and always had been.
It wasn’t perfect, but we kept the illusion going; objects didn’t know, or care if they had been persisted, the data store was garbage collected (mark and sweep, triggered by asking Pixie to run a sweep for you), objects were unique – you’d never have two objects in memory with the same id.
Quite deliberately, we didn’t have a query language; the idea was that you got into the data store through known entry points and, if you needed to do searching or indexing or whatever, you could write your own. The plan was to discover what sort of searching would be needed, and implement that.
As ‘one to throw away’ I’m really rather proud of Pixie. It fell down on locking – we tried to add it later, and that really, really didn’t want to work. If I were starting with a clean sheet, I’d worry about that far earlier and probably try and use optimistic locking to implement something transaction – there’s at least one Smalltalk persistence engine that has some good ideas here, I just can’t remember what it’s called.
I’d also look at a hybrid scheme. Pixie was essentially one big table with an id column and a blob – not exactly scalable. With a sensible scheme for describing classes, it should be possible to have one big table for some objects and ActiveRecord type tables for things that you want to search. Jifty’s persistent objects do some very clever things in this regard.
Metadata would be useful in another respect too. ActiveRecord’s validations, errors and helpers like input 'variable', 'field' all use a pretty restricted set of ActiveRecord metadata. A class description language (or an appropriate set of class methods) that could implement compliant columns, attributes and the others could be very useful…
I suppose the question is, could I implement it? Pixie poked in some very odd corners of Perl to get the behaviour we needed. One example was the mementos that could replace themselves with the ‘real object’ they’d fetched from the database. They were all instances of Pixie::Cookie with an AUTOLOAD – perl’s equivalent of method_missing that went to the database for the data, populated its ‘instance variables’ and then changed its own class to ‘become’ an instance of the appropriate class.
Hmm… I feel the need for a spike…
1 There’s lots of stuff that niggles me about rails. Nothing that makes me want to throw it out and start using something else – yet, but I’m still waiting for Perl 6.
That's not fluent... 13
So, I’m not a fan of static typing. It’s okay in the likes of Haskell which does type inferencing and generally goes out of its way to reduce programmer pain, but Java? C#? No ta. It’s awfully tempting to conclude that anyone who chooses to use those languages deserves to be pointed out and laughed at.
It’s especially hard to resist that temptation, when a C# blogger plays right into my hands by describing the following code:
Pattern findGamesPattern = Pattern.With.Literal(@"<div")
.WhiteSpace.Repeat.ZeroOrMore
.Literal(@"class=""game""").WhiteSpace.Repeat.ZeroOrMore.Literal(@"id=""")
.NamedGroup("gameId", Pattern.With.Digit.Repeat.OneOrMore)
.Literal(@"-game""")
.NamedGroup("content", Pattern.With.Anything.Repeat.Lazy.ZeroOrMore)
.Literal(@"<!--gameStatus")
.WhiteSpace.Repeat.ZeroOrMore.Literal("=").WhiteSpace.Repeat.ZeroOrMore
.NamedGroup("gameState", Pattern.With.Digit.Repeat.OneOrMore)
.Literal("-->");
as “a very nice regular expression wrapper which allows you to define a regex using a readable syntax exposed via a very elegant fluent interface”. It seemed so self-evidently silly that I read back in his blog to see if he was taking the piss. Depressingly, he appears to be serious. Ah well, I shall at least resist the temptation of supplying his name and URL.
Worse, he’s using this regular expression (Rendered in Perl’s /x style, which ignores whitespace and allows comments in the body of the regex)
qr/
<div
\s* # can match the empty string!
class="game"
\s*
id="(\d+)-game"
(.*?)
<!--
gameStatus \s* = \s* (\d+)
-->
/msx
to parse XML (one of the canonical no nos that one). Badly. For instance, it will match this drivel:
<divclass="game"id="0-game"<!--gameStatus=10-->
but it won’t match this perfectly valid xml:
<div id="1-game" class="game">
stuff
<!--gameStatus=10-->
</div>
On reflection, that might not be matched for a couple of reasons – it depends whether Anything includes "\n".
All of which is beside my main point. The sheer wordiness of the ‘fluent’ regex wrapper serves merely to obfuscate the intent of the pattern. You are tempted to conclude that, if it has that many words in it, it must be correct. This isn’t so much fluent as effluent.
Meanwhile, in that bastion of ‘line noise’ that is Perl, Damian Conway’s Perl Best Practices recommends writing all but the most trivial of regular expressions using the a standard set of switches (msx) and using whitespace to break the pattern up into logical chunks with comments where necessary. Given that almost everyone uses PCRE nowadays, you can follow the same good practice in your language of choice.
Yes, the regular expression language is terse. Yes it can be opaque until you take the time to learn its grammar. But there aren’t that many rules to learn. The language isn’t complex, only some of the things that people use it for.
What is fluency then?
An interface isn’t fluent because it’s wordy. Fluency is about writing message protocols that make it easy for the user to solve her problem and clearly express her intent in the same bit of code. Frankly, plain old regular expressions are a damned sight more fluent in all their terseness than the above bad joke.
DSLs, Fluent Interfaces, and how to tell the difference
I’m getting heartily fed up of people banging on about Domain Specific Languages. It seems that every time someone writes a Ruby library that uses class methods, symbols and hashes reasonably sensibly they get delusions of grandeur and call the result a Domain Specific Language (or maybe an ‘embedded’ DSL).
In a sense, they’re right, but it’s a pretty compromised language simply because you’re stuck with the Ruby parser. Scheme and Lisp hackers probably look at (say) ActiveRecord and sneer. Heck, even Perl programmers have grounds for getting their sneer on
Now, before any Ruby programmers go getting on their high horse about Perl programmers being indisciplined louts, may I refer you to Getopt::Euclid, an alternative to Perl’s Getopt::Long library.
Getopt, or something like it, is pretty much a universal among programming languages. It’s the library that makes it ‘easy’ to write commandline programs with unix style switches. It’s often one of those functions that ends up taking an ugly argument string which defines all the possible flags your command could have. As interfaces go, it’s often actively user hostile – the argument string is a DSL, but it’s one that took its design cues from the notorious sendmail.cf.
So, Damian Conway fixed it. To use Getopt::Euclid you just import the library and then write your command’s documentation using Perl’s inline POD with a couple of extra Euclidean extensions and you’re done. Getopt::Euclid treats your documentation as its specification and builds its option parser from that.
Now that’s what I call a DSL. Entirely embedded in the Domain Specific (natural) Language of documenting a command line program.
Damian’s a genius at this sort of thing. Check out List::Maker, where he finds a little used part of perl’s syntax and wedges in a bunch of cunning ways of building lists, including something that looks remarkably like list comprehensions.
And this is in Perl 5; the version of the language that doesn’t have explicity support for syntax modification.
Another example of the kind of thing that’s possible without monkeying with the parser is the stuff Jifty (originally JFDI), in particular the way Jifty Schemas work.
What’s my point?
I’m not saying don’t take the time to make your interfaces ‘language like’. However, there’s a lot to be learned from the way other languages have approached the idea of the DSL or ‘little’ language. Implementing something like Jifty’s Schema’s in Perl is far from easy (though the techniques needed are getting better understood all the time) and involve ferreting around in dusty corners of an already arcane syntax, but the beauty of getting it right is that you simply don’t have to care about how its implemented. The neat bit, the bit that’s worth pinching is the syntax of the resulting DSLs…
Oh yes, and, while you’re about it, take a look at what Why the Lucky Stiff is doing with hpricot, definitely one of those libraries that goes out of its way to make life easy for its users.
Crossing the Rubicon. Again 5
In 2001, using an idea from James Duncan, who blames Damian Conway for getting him thinking on the right lines, I wrote a proof by implementation of the Extract Method refactoring for Perl. Though I say so myself, this was a Big Deal – Martin Fowler calls Extract Method the Refactoring Rubicon – once you have a tool to help you do that refactoring automatically, you can probably implement the rest of the Smalltalk Refactoring Browser and free yourself to think more about the interesting aspects of programming.
And nothing happened.
Five years later, I mentioned this to Jesse Vincent at EuroOSCON. He got that “You interest me strangely!” look, so I verbally sketched out how it worked, which induced the “I must hack now!” look. I headed off to another session and left Jesse to scratch his itch.
About 3 hours later, we hooked up again, and he showed me the vi plugin he’s hacked up which implements an ‘extract function’ refactoring. So we sat down together and made it extract a method correctly.
At this point, magic happened. Jesse’s original script was, putting it politely, very hacky. It’s less hacky now, in part because it’s been refactored with the assistance of this cool new tool he’d just written to extract methods from Perl code.
Ruby 'til 6 1
Oh, I say. It seems that Sam Ruby is another member of the “Ruby ‘til [Perl] 6” club.
I like Ruby a lot. For the kind dynamic OO/Functional coding style that I espouse, it’s a better Perl than Perl simply because it’s so much less verbose (I got so tired of always unpacking the argument list, it tended to put me off applying the Composed Method pattern anywhere near often enough).
But it’s not my One True Language. Perl 6 looks like it might be an awful lot closer to it. If nothing else, it has Lisp style macros.
A good macro system, especially when it’s combined with an accessible and well abstracted runtime is an awfully useful thing. For instance, consider the Rails controller. In a rails controller, public methods are ‘visible’ as actions that can be accessed via the web (usually with a url of the form /:controller/:action). Protected and private methods aren’t accessible in the same way.
But sometimes it’s quite handy to have a method on the controller that shouldn’t be deemed to be an action, but which you might want to call from a model. The canonical example here is when you’re doing Double Dispatch. Here’s an example of bad code:
results = @search_results.collect do |item|
case item
when Comment: extract_comment_metadata(item)
when Trackback: extract_trackback_metadata(item)
else
fail "Oops!"
end
endLook, we’re using a case statement that dispatches on the class of another object! This is a job for Polymorphism. Let’s assume that the two extract_*_metadata methods need to do some of the things that only a controller can and can’t simply be replaced with extract_metadata on the Comment and Trackback objects. Here’s how I’d rejig the controller code:
results = @search_results.collect {|item| item.extract_metadata_for(self) }And the support code in the model classes looks like1
def Comment::extract_metadata_for(controller)
controller.extract_comment_metadata(self)
end
def Trackback::extract_metadata_for(controller)
controller.extract_trackback_metadata(self)
endAnd look! I’ve saved a line of code! Except, it doesn’t quite work like that. The extract_*_metadata methods aren’t public, we’re not supposed to call them from the model, so we’ll have to work around it:
def Comment::extract_metadata_for(controller)
controller.send :extract_comment_metadata, self
end
def Trackback::extract_metadata_for(controller)
controller.send :extract_trackback_metadata, self
endwhich isn’t the end of the world, but it does obfuscate an idiom that’s already unfamiliar to many readers. Not good.
If you were writing Rails in Smalltalk, you would just file your controllers web visible actions in an ‘actions’ protocol and have done with it. If you were writing it in Perl, you could use method properties, declaring actions with something like:
sub read :action { ... }Sadly, ruby doesn’t have method properties. What I’d like to be able to write is something like:
action read
...
endAnd have that define my action and do the housekeeping so that the rest of the framework knows that it can dispatch to this from a web request. About the nearest you could get to this with current Ruby is:
action :read do
...
endIt’s not awful, but it’s not pretty either.
A good macro system would make it let you write things that feel even more like part of the language than the many excellent things that Ruby on Rails already does in this area.
Another example: I would dearly love to be able to ‘unwind protect’ my controller’s filter methods, it’d be great if I could write:
pre_filter whatever
allocate_a_bunch_of_resources
true
unwind_protect
tidy_up_allocated_resources
endThe idea being that, if a filter block returns false, or throws an exception, we walk back up the stack of filters that have been called and execute their unwind_protect blocks. Admittedly, this sort of thing wouldn’t be terribly easy to write with a macro system, but I’m not sure it’s even possible to write without one because you need to preserve the value from just before the unwind_protect to return to the filter’s caller. You’d have to move your unwind_protect earlier in the code:
pre_filter :whatever
def whatever
unwind_protect do
tidy_up_allocated_resources
end
allocate_a_bunch_of_resources
true
endBut that feels arse about face, and I don’t know how you’re going to catch any exception thrown by allocate_a_bunch_of_resources. I suppose you could do:
pre_filter :whatever
def whatever
unwind_protect do
tidy_up_allocated_resources
end
allocate_a_bunch_of_resources
true
rescue Exception => e
tidy_up_allocated_resources
raise e
endBut by now we’re looking at code that only a mother could love, and even then she’d need a pretty high tolerance threshold.
Macro systems let you play these sorts of games, they’re just another tool for molding the language into something that makes it easy to solve the sorts of problems you face from day to day. One of the great things about using Ruby on Rails is that DHH and his cohorts have done a fabulous job of language design. Rails contains a host of handy domain specific languages (the most obvious being the stuff for declaring object relationships in ActiveRecord, but there’s some very handy stuff in the tag building and RJS support libraries as well) that work well together and allow the programmer to concentrate on solving his particular problem. It’s just that on occasion, it would be nice if they could go that one step further.
Perl 6 will let me take those sorts of steps.
I’d just like to say to any schemers/lispers who’ve made it this far: “Yes, I know.”
1 It doesn’t quite, I’ve taken liberties with the def syntax to preserve some vertical space…
Perl Glamour
Photos by Piers Cawley. CC Licenced, though I bet he didn’t think I was going to do this with them.
—Photo Credit at Love Perl
Too right I didn’t expect anyone to do that with them. I’m awfully flattered though. I look forward to St. Valentine’s day.
It’s a shame there’s no Perl Advent Calendar this year though.
Perl 6 Summary: Week ending 2005-11-27
Another week passes. Another summary is written. Another sentence is written in the passive voice.
This week in perl6-compiler
Perl 5 tests for PGE::P5Regexp
Jerry Gay announced that he’d checked in a subset of perl 5.9.2’s regexp tests to give PGE something to work on. Right now only 130 of 960 tests are running, in part because the test harness he’s using can’t quite cope with the test file syntax used for the original tests. I’m sure it won’t stay that way or long.
A couple of days later he announced that more tests were being converted and that there were now 360 passing tests and a further 155 or so TODO tests.
Well done Jerry.
http://groups.google.com/groups?threadm=1d9a3f400511211939i134aa0fnefc86179431b96fd@mail.gmail.com
PDD 20 and :outer
Leo had some questions about the workings of lexical pads and :outer. He
showed a couple of examples in high level language and wondered if his parrot
conversions were right. Chip thought that Leo shouldn’t worry about
implementing the Perl 5 semantics of a named inner subroutine because the way
Perl 5 does it is a bug not a feature. Dave Mitchell wasn’t so sure.
http://groups.google.com/groups?threadm=43832AF2.2040402@toetsch.at
DynLexPad
Leo’s working on implementing a DynLexPad PMC to provide ‘a more dynamic lexpad’ akin to the new deprecated ScratchPad PMC. He outlined his current plans and asked for comments from HLL authors about what they needed.
http://groups.google.com/groups?threadm=43834203.2020209@toetsch.at
Punie to AST
Allison has checked in the code to transform PunieGrammar match objects into Abstract Syntax Trees (ASTs). Apparently the set of AST node types she’s using isn’t quite the same as the Pugs PIL. Hopefully one day we’ll have a common AST format, and all manner of things shall be well.
http://groups.google.com/groups?threadm=FE692303-15F8-42D8-AF73-270BCEDA6EAD@perl.org
Meanwhile, in perl6-internals
RESPONSIBLE_PARTIES or ENTITIES_AT_FAULT?
Joshua Hoblitt suggested that Jerry Gay should be added to the
F
http://groups.google.com/groups?threadm=20051120210940.GB22898@ifa.hawaii.edu
Curses and parrot problems?
Josh Isam has been having problems with using the curses library under both Darwin and freebsd. He wondered if anyone had any pointers for fixing things. Leo thought it might be that the parrot ncurses support was getting a function signature wrong somewhere and suggested Josh check that.
http://groups.google.com/groups?threadm=Pine.LNX.4.53.0511222245480.1385@ritalin.shout.net
Subs may not contain dynamic call info, ever
Repeat after Chip: “Subs don’t have callers. Call frames have callers.”
After a short discussion with Leo, Chip wrote a short treatise on the relationships between Subs and Closures, noting that they should only hold static information.
http://groups.google.com/groups?threadm=20051123180834.GF6095@tytlal.topaz.cx
Undefined labels
While working on TODO #37590 (catch illegal bsr at compile time), Leo’s made parrot rather more picky about labels and how they are used. Essentially, if you weren’t doing daft things with labels you’re probably all right. If you were, you should probably check this post.
After Leo checked the fixes in (r10168), several PGE tests started breaking. Less than 6 hours later, Patrick check version r10176 in and the tests started passing again. Leo (and I) was impressed.
http://groups.google.com/groups?threadm=87bc76ce931e9c7e29ed9be192d32de4@toetsch.at
http://groups.google.com/groups?threadm=3a149d0a332aa57205267f928fe1544a@toetsch.at
Exception handlers and calling conventions
Leo posted a brain dump about how to get exception handling to work in Parrot. In particular he wanted help with syntax (exception handling semantics aren’t exactly rocket science when you’ve got a continuation based virtual machine after all). Warnock applied (However, I am reliably informed that next week’s summary will have some responses; anyone who suggests that that’s because this summary is late will be annoyingly Right).
http://groups.google.com/groups?threadm=5b4f21642641211939b10fe8548ea876@toetsch.at
Test::More and tests in PIR
Not content with having a pure PIR implementation of Test::Builder, chromatic posted his implementation of Test::More in pure parrot. Admittedly the current version should likely be called Test::Less::Is::More, but the journey of 1000 cliches starts with a single step and all that. And that’s not all, the fearlessly lowercased one intends to start work on the big daddy, Parrot::Test with an eye to doing even more in Parrot. (Which makes a good deal of sense. After all, the plan is to get Parrot to a point where it can be built without needing a working perl installation)
http://groups.google.com/groups?threadm=1133039776.6474.48.camel@localhost
Meanwhile, in perl6-language
\x{123a 123b 123c}
Juerd had praised Ruud H.G. van Tol’s proposal of \x{123a 123b 123c} as a
replacement for \x{123a} \x{123b} \x{123c} in rules. Larry wasn’t so
sure. He suggested \x[123a,123b,123c] but still wasn’t exactly happy with
it. He also had some thoughts about character class syntax, and the meaning of
spaces within a character class spec. This being the language list, the
discussion spun off in various directions (all related to rules, just not
necessarily that much to do with the nominal subject). It was good stuff
though; threads with Larry, Damian, Patrick and Luke in them usually are.
One little tidbit that came out of this was a reminder that the best place to read synopses and apocalypses is at svn.perl.org or dev.perl.org because they are kept up to date, unlike the ones at perl.com.
http://groups.google.com/groups?threadm=20051120023217.GA507@wall.org
Multidimensional argument list binding
Ingo Blechschmidt’s question from the end of last week about multidimensional
argument list binding got addressed this week. He, Luke and Larry discussed
different aspects of slurpiness. Personally, I expect I’ll be using the
*;foo@ for almost all my slurpy needs.
http://groups.google.com/groups?threadm=dlql9i$bnf$1@sea.gmane.org
statement_control<foo>()
Ingo Blechschmidt had asserted that for is not strictly a Perl 6 keyword,
but is (conceptually at least) at statement control subroutine. Rob Kinyon
wondered what other ‘keywords’ were actually statement control subs. According
to Ingo, pretty much everything that’s used for control flow modification is a
statement control subroutine, but that they’ll almost certainly be optimised
away to ‘primitives’ of some sort (after all, it’s rather hard to come up with
a definition of if, say that isn’t at least slightly circular).
http://groups.google.com/groups?threadm=70384420511202024y223ac219h3ecea2cbd0feef8@mail.gmail.com
till
Perl 6’s stock of agricultural operators continues to grow apace. Not content
with gather, we now have C.. (sorry beachware fans).
Larry had some thoughts on the detailed semantics in response to a question
from Ingo. Most of Ingo’s problems disappeared when he realised that till
would be a macro.
http://groups.google.com/groups?threadm=20051121062128.GA9451@wall.org
Ponie!
Joshua Gatcomb wondered what was happening to Ponie and if Fotango would continue to fund it. Warnock applies.
http://groups.google.com/groups?threadm=941eab840511211220t1ee6952dpb578ed10259f29@mail.gmail.com
Dis-junctive patterns
Gaal Yahas found what looked like a bug in pugs. Larry agreed that it looks pretty entomological. It’s probably already fixed in bleadpugs.
http://groups.google.com/groups?threadm=20051122073126.GE14252@sike.forum2.org
Type sigils and a new unary ^ operator
Larry announced that, after all the discussion of coming up with a type sigil
and searching for various possibilities, he’s ended up back at ::, which was
what it was before the discussion started. Apparently the tipping point came
when he realised that he wanted ^$x back as a unary operator that’s short
for 0..($x-1) which would make it easy to write things like:
for ^5 {...}
without falling foul of fencepost errors etc. Some people didn’t like it. Vocally. Larry stood firm. Yay Larry. (Impartial summarizer? What’s that then?)
http://groups.google.com/groups?threadm=20051122223412.GA28366@wall.org
Lazy lists in Str context
Flavio S. Glock reckoned it would be nice if:
say substr( ~(1..Inf), 0, 10 )
printed “1 2 3 4 5”. There was discussion, but I think we stayed firmly in “Not going to happen.” Unless I completely misread the thread of course.
http://groups.google.com/groups?threadm=aa47605d0511230413p20173745k@mail.gmail.com
Binding of list slice elements
Ingo Blechschmidt is great at posting a few lines of not particularly mind bending code and then following consequences through until either your mind is broken, or you assume that Ingo’s must be (more usually the former than the latter, to Ingo’s everlasting credit).
This time he followed through on the implications of binding array slices. Nothing from @larry yet, but he posted at the end of the week.
http://groups.google.com/groups?threadm=dm4has$u3s$1@sea.gmane.org
Acknowledgements, apologies and everything else
This summary was made from the finest mailing list posts, each individually plucked and filleted for your delight and elucidation. The alert among you will have noted that today is Wednesday and not Monday, which means we’re a little late. What can I say? It’s ready when it’s ready.
This summary was also brought to you through the labours of Piers Cawley and not Matt Fowles as we had planned when, dewy eyed and innocent, I set off on the long journey down to the wilds of London with the express intention of attending the London Perl Workshop, the International Magic Convention, Sharp’s folk club and divers fine gentlemen’s outfitters, jewellers, bookshops and quality eating establishments.
All was proceeding flawlessly, until, on Saturday morning as the tube train doors began to close in front of me, I attempted to stop running and discovered that the soles of my shoes had other ideas and fell on my arse, twisted my ankle and scraped an unfeasibly large amount of skin from my shin off on the bottom of the aforementioned tube train. Luckily the driver noticed my plight and did not drive off, taking my left foot with him. Instead he opened the doors and waited for me to dust myself off and board his vehicle, which carried me to Paddington where, after much hobbling and swearing I was bandaged and deposited once more on London’s cold and unfeeling streets.
So, I hopped into a taxi (and I use the word hopped advisedly) and repaired straightway to King’s Cross and thence home to Gateshead, where my discomfort was somewhat ameliorated by the distraction of preparing this week’s summary. I hope to be writing next week’s summary as well because the week after I’ll be moving house and don’t quite know when I’ll have my bandwidth back.
Help Chip
http://geeksunite.org/—Chip still needs help.
The usual coda
If you find these summaries useful or enjoyable, please consider contributing to the Perl Foundation to help support the development of Perl.
http://donate.perl-foundation.org/—The Perl Foundation
http://dev.perl.org/perl6/—Perl 6 Development site
Check out my website, it’s lovely.
Vaguely pretty photos by me can be found at:
Perl 6 Summary for the fortnight ending 2005-11-13
Welcome to another fortnight’s worth of summary. We’ll get back to a weekly schedule one of these fine days, you see if we don’t.
This fortnight in perl6-compiler
There was a surprisingly large amount of activity on the list, but again, the place to look for perl6 compiler news is the Planet Perl Six aggregator.
PGE improvements and changes
Patrick announced that he’d checked in some major changes to the PGE
internals. The changes include a shiny new shift-reduce operator precedence
parser which is used to parse the rules themselves. PGE finally has a
<p6rule> parsing rule which can be used to parse a valid Perl 6
rule. There are other changes, but those two are the headlines. Patrick asked
for the usual questions, comments, patches and tests.
A couple of days later, he posted a more comprehensive overview of the new and shiny bits in PGE.
http://groups.google.com/groups?threadm=20051101062541.GA30198@host.pmichaud.com
http://groups.google.com/groups?threadm=20051104144923.GA12353@host.pmichaud.com
PGE problem with non-greedy quantifiers
Allison fell foul of some changes in the new PGE. This turned out to be a bug in PGE, so Patrick fixed it.
http://groups.google.com/groups?threadm=ED559257-B0D9-4216-98E4-88C0AC3B4F0F@perl.org
The meaning of \n and \N
Noting that Synopsis 5 says that ‘\n now matches a logical (platform
independent) newline, not just \012’, Patrick asked the list for more
details about what that should mean so he could get on and implement it in
PGE. He offered up a suggested matching rule. Larry thought that the suggested
rule was close enough for jazz.
http://groups.google.com/groups?threadm=20051104155307.GA15393@host.pmichaud.com
[] and () on rule modifiers
Patrick continues to work on the PGE. This time he asked about the behaviour of
rule modifiers, with particular reference to the :w modifier. Larry had
answers.
http://groups.google.com/groups?threadm=20051104192614.GA30432@host.pmichaud.com
Parrot 0.3.1 “Wart” released
Leo announced the release of Parrot 0.3.1 “Wart”, complete with shiny new features like variable sized register frames and no more spilling, a much better PGE (see above) and other goodies. The latest release has more than 3000 tests, and that’s probably still not enough.
http://groups.google.com/groups?threadm=436E0DBB.8040300@toetsch.at
Octal in p6rules (and strings)
Patrick Continued his voyage of stringy discovery, this time asking about the
black art of specifying glyphs/bytes/whatever using octal notation. He wondered
about his assumption that the correct way to do it is with \o123 by analogy
with using 0o123 to specify a number in octal. He also wanted confirmation
that the \nnn notation had been dropped. A surprisingly long discussion
ensued as Larry did a good deal of thinking aloud and Patrick got on with
implementing the nailed down bits.
http://groups.google.com/groups?threadm=20051107165159.GA13344@host.pmichaud.com
Meanwhile, in perl6-internals
SWIGging Parrot
John Lenz is one of the developers a SWIG, which started off as the Python equivalent to Perl’s XS. He had some questions about writing a SWIG module for parrot and asked if there would be interest in having SWIG be one of the ‘official’ ways of doing native calls from Parrot. Leo thought not, pointing out that Parrot’s NCI is fully dynamic and groovy.
http://groups.google.com/groups?threadm=35051.192.168.0.12.1130741345.squirrel@192.168.0.2
NCI using ffcall library
Garrett Goebel joined in the ongoing discussion of using ffcall to implement the Parrot NCI (Native Call Interface) by pointing back to an earlier discussion of using libffi to implement the Parrot NCI. Last time round, Dan had pointed out that, because libffi is an external library, there still needs to be a supported (if possibly hackish) way of doing NCI that comes with Parrot, but that configure could probe for external libraries to use where they are available.
http://groups.google.com/groups?threadm=E4901162278E99499731C168EC803B59991554@mail.scriptpro.com
Heredocs in function calls
Patrick wondered if there might be a convenient way to support heredoc parameters in PIR function calls. Nicholas Clark wondered why one would bother since most PIR code should be generated code.
Later on, Leo implemented them. About the only place they don’t work now is in macro arguments.
http://groups.google.com/groups?threadm=20051101074509.GA1506@host.pmichaud.com
http://groups.google.com/groups?threadm=4369CBC7.1070407@toetsch.at
Simple register allocation
Summarizing a discussion on IRC, Patrick noted that it would be nice if the PIR compiler had a way to use a very basic register allocation for .subs that only use a small number of registers. After all, there’s little point in doing a complex analysis of control flow if a sub uses (say) 5 registers at most. The problem is that this analysis gets harder as the subs get longer (O(n) on the length of the sub). In the case of PGE (for instance), the subs can get very long, with lots of control flow statements, but use a maximum of 10 PMC, 9 int and 4 string registers for the whole thing.
Warnock applies.
http://groups.google.com/groups?threadm=rt-3.0.11-37578-123722.7.0478443353673@perl.org
Careful with that bsr Eugene
Leo noted that, with the introduction of variable sized register frames, it is
no longer legal to bsr into a different .sub.
http://groups.google.com/groups?threadm=ce791f585f2d5b3ae727692fa6476666@toetsch.at
Reconfiguring configure
Joshua Hoblitt sketched out a route map for getting from our current ‘built to throw away’ configuration system to the sunny uplands of the miniparrot based config system. Everyone who commented sounded positive. Now, if someone could just implement it…
http://groups.google.com/groups?threadm=20051103073105.GB16634@ifa.hawaii.edu
Shifting right by more than the width of int
Joshua Isam had problems doing a right shift of more than the width of an integer. Which is no surprise really as the behaviour is officially undefined in the C spec, which is the implementation that Parrot uses. There was some discussion, but the consensus is that it’s best to stick with the C semantics for integer registers and if the need arises for more complex semantics, it’s always possible to write a new PMC.
http://groups.google.com/groups?threadm=740b6a05281f1e3f3b54cd7791838a51@ritalin.shout.net
Suspend and resume opcode
Tomo sent in a patch implementing suspend and resume opcodes. After a
certain amount of kerfuffle involving the mailing list software stripping troff
attachments and dodgy software deciding that a .t file full of tests was
actually a troff source, Leo rejected the patch and pointed Tomo in the
direction of coroutines.
The mailing list will now accept troff attachments. Hurrah.
http://groups.google.com/groups?threadm=436B403C.2000307@nekomimists.ddo.jp
Creeping up on ffcall NCI
Nick Glencross posted another update of his work on getting NCI to use the ffcall library. He’s now added config smarts to detect the ffcall and other handy features.
http://groups.google.com/groups?threadm=dcb629180511040927kd7042f2vdb722f49a4df2a9a@mail.gmail.com
Removing unmaintained languages from parrot tree
Jerry Gay noticed that there were an awful lot of unmaintained languages in the Parrot tree. He recommended getting in touch with their last known authors and eventually removing the dead languages.
http://groups.google.com/groups?threadm=rt-3.0.11-37611-123890.17.8232124086628@perl.org
Testing non-core PIR libraries with Parrot::Test
Allison outlined some of the problems she’d been having testing her tree transformation engines outside of the parrot tree. It turns out that Parrot or the Test tool require absolute paths to various libraries, which is no fun at all. She suggested fixing Parrot::Test up so as to try and divine (and set) a sensible load path for Parrot. Meanwhile, chromatic continues to beaver away at implementing Test::More in PIR.
http://groups.google.com/groups?threadm=D3C8F121-06ED-40BF-B5E4-DB94D0414B12@perl.org
Updating parrotcode.org
Will Coleda announced that he’d been doing some tidying up of the parrotcode.org website and asked for suggestions for an updated ‘where we are’ section. Various answers and suggestions were provided.
find_type considered dubious
Roger Browne was puzzled by the behaviour of the find_type opcode, which
works for both PMC types and native Parrot types. He thought that this was both
confusing and counter productive. Leo didn’t seem to agree with him.
http://groups.google.com/groups?threadm=1131544548.7662.9.camel@eiffel.demon.co.uk
Unicode strings and encodings
Leo announced that he’s going through the various string functions to make them usable with all the string encodings we know about. He outlined what he proposed to do solicited comments in case of insanity.
http://groups.google.com/groups?threadm=437353FF.5020106@toetsch.at
Legal names for PMCS
Roger Browne (whose name I keep wanting to use as a Clerihew) wondered what the
rules were for naming PMCs. Leo reckoned that, unless someone rejigs
pmc2c.pl to mangle non word characters appropriately, a PMC name should
follow the same rules as C identifiers.
http://groups.google.com/groups?threadm=1131707019.23357.6.camel@eiffel.demon.co.uk
string_bitwise_*
Noting that, with ICU installed, parrot has ‘rather complete support for Unicode string manipulation’, Leo wondered about making the bitwise string manipulations work. In particularly, he wondered how they should behave in the face of charset and/or encoding mismatches. According to Leo, it seems to boil down to a choice between throwing an exception or simply mashing everything together and marking the ‘resulting bit mess’ as binary. Warnock applies.
http://groups.google.com/groups?threadm=4375E49D.5060405@toetsch.at
Parrot fink
Will Coleda passed on a query from the #parrot irc channel. Someone had wondered if there was a Fink build of Parrot available. (Fink is an OS X open source package manager along the lines of, well, pretty much every other package manager). There isn’t, so Will wondered if there was anyone on the list who could help put one together. Leo noted that Parrot is already Debianized (yay!) which might help with the fink approach too. Joshua Isam worked on the task.
http://groups.google.com/groups?threadm=AD8403CA-D106-414E-8D85-DE525AEA37BD@coleda.com
Changing default STDOUT/STDERR Filehandles for PIR code
One of the things that chromatic needs in order to write a pure PIR version of Parrot::Test is a way to redirect STDOUT and STDERR within a section of PIR code. He’s looked at the implementation of the ParrotIO PMC and the print opcode, but can’t see where to begin. So, he asked for help. At close of play on Sunday there had been no answer, but I’m sure someone will be along soon.
http://groups.google.com/groups?threadm=1131833503.24170.5.camel@localhost
PDD20: An idea: Call frames as PMCs
Chip led the applause for Leo’s implementation of the new lexical scheme in all of a week. He then went on to outline an idea for turning call frames into PMCs. Leo wasn’t sure, pointing out that the call frame would have the same issues as promoting a continuation. I have to confess that I’d tended to assume that the PMC that Chip’s proposing already exists, and it’s called a continuation.
http://groups.google.com/groups?threadm=20051113034521.GC6553@tytlal.topaz.cx
:outer("foo") is working
Leo announced that :outer("foo") now works, with a couple of caveats.
http://groups.google.com/groups?threadm=437734FF.40203@toetsch.at
Meanwhile, in perl6-language
Ways to add behaviour
The problem with summarizing an ongoing thread that you’ve not really been following is getting the context again. I have to confess that, when I returned to the ‘Ways to add behaviour’ thread this week I was somewhat stumped. Thomas Sandlass and Larry appeared to be having fun with terminology and type algebra. I’m sure that we’ll end up with a more robust language as a result of all this, but it doesn’t mean I could follow the discussion as it was happening.
http://groups.google.com/groups?threadm=20051026173441.GB29341@wall.org
$_ defaulting for mutating ops
Remember last time? Juerd had proposed that mutating ops like ++ default to
mutating $_ in the absence of a left hand argument. It seems that the
discussion convinced Juerd that it wasn’t a good idea after all. But, this
being perl6-language, it also seemed to convince others that it is a good idea.
http://groups.google.com/groups?threadm=Pine.LNX.4.33.0510280955200.28049-100000@sharkey.morinda.com
Role method conflicts and disambiguation
Discussion of how to handle conflicting role methods and their disambiguation continued. Unless I’m going soft in the head, I could have sworn that the original Smalltalk ‘Traits’ paper (they’re called Roles in Perl 6 because we already have Traits) dealt with disambiguation in a fairly straightforward fashion. I continue to be reminded of the same joke as last week.
http://groups.google.com/groups?threadm=20051101091913.GB4058@woobling.org
Co/contra variance of roles/factories in theory.pod
Err… I haven’t the faintest idea what Luke and Thomas Sandlass are talking about here. Luckily, it seems that Larry did understand it.
http://groups.google.com/groups?threadm=436A5291.7010205@orthogon.com
Perl 6 perlplexities
Michele Dondi worries that the increase in complexity of some aspects of Perl 6 is much bigger than the increase in functionality that the complexity buys us. In particular Michele is concerned that the Perl 6 parameter passing and signature stuff is going to be a big loss. People mostly disagreed with him. Rob Kinyon made a remark that chimed strongly with me, pointing out that Ruby’s OO system is substantially more complex than Perl 5’s, but that it’s also a great deal easier to use. (Rob’s not alone in this, I am writing most of my new OO code in Ruby. I fully expect to switch back to Perl 6 as soon as it becomes good enough though).
Lots of good discussion here. I was convinced once again that Perl 6’s signatures are going to be the best thing since sliced bread. Even if I do still like Smalltalk method selectors best of all.
http://groups.google.com/groups?threadm=Pine.LNX.4.62.0510211140010.21523@spock.pcteor1.mi.infn.it
Implicitly doing a role
If a tree falls in a forest with no one to hear it, does it make a sound? If a class implements the same interface as a role without saying that it does, does it still do the role? One of these philosophical questions was asked by Austin Frank. The other is a timeless wossname. Can you guess which is which?
Rob Kinyon thought that the answer to the second question was ‘no’. So did chromatic, citing the usual Dog/Tree problem with ‘bark’. After further thought, chromatic proposed that a class should create an implicit empty role of the same name to make things easy for people writing mock objects and other entertainingly different variants of the original class.
Decorated Dog anyone?
http://groups.google.com/groups?threadm=436BA54F.9040501@gmail.com
The new class sigil
Remember when the new class sigil was going to be ¢? Well, we’re still getting one, but it’s called ^ now. I think.
http://groups.google.com/groups?threadm=436BB303.4080502@orthogon.com
Private methods and role composition
Jonathan Lang wondered if there was a way of declaring a method as private to a role, and a role could reclassify a composed method as private. Larry answered ‘yes’ to the first question and ‘no’ to the second.
http://groups.google.com/groups?threadm=ef30550b0511051135q5fe874c7t5c2027b2e5a9c7f3@mail.gmail.com
=>’s container and binding semantics
Ingo Blechschmidt had some questions about modifying pair keys and values and about the semantics of binding to a pair value. Larry had answers. And interesting implicit questions.
http://groups.google.com/groups?threadm=dkl2t3$19o$1@sea.gmane.org
Default values for instance variables
Gaal Yahas thinks it’d be nice to supply default values to instance variables at declaration time. Luke pointed out that it is actually legal to do just that in Perl 6, but that pugs doesn’t yet implement it.
http://groups.google.com/groups?threadm=20051108160826.GD15437@debian
Proposal: rename ‘subtype’ declarator to ‘set’
Undeterred by the fact that the OED has eight distinct headword entries for
‘set’, covering four different parts of speech and a prefix form, Thomas
Sandlass proposed changing the subtype declarator to set. Larry agreed
that it might be a way forward, but worried about interference between the
declarative form and the verb ‘to set’. Stuart Cook thought that ‘subset’ might
be slightly less confusing, but Eric the Surnameless thought that that would be
more confusing.
http://groups.google.com/groups?threadm=4371EF61.10107@orthogon.com
Test case: Complex numbers
Jonathan Lang posted a skeleton implementation of complex numbers and their associated arithmetic to the list as a possible test case of various Perl 6 goodies. Luke and Larry both offered comments and suggestions.
http://groups.google.com/groups?threadm=ef30550b0511091821r27f61704m852f3b1d5d31dcf1@mail.gmail.com
Given too little
Gaal Yahas seems to have found a possible bug in pugs when using when with an
expression that returns a boolean. It turns out that this might be a bug in the
spec. Getting the semantics of ~~ nailed down so that when always does the
Right Thing is Hard. Larry’s working on it. One fix seems to be to shove the
conditional code into a block. The block is then evaluated (possibly with the
$_ as an argument) and ~~ returns true if the block returns true.
http://groups.google.com/groups?threadm=20051110083149.GJ15437@debian
What’s the latest on Iterators
Joe Gottman is worried that the various synopses make plenty of references to
Iterators, but that Iterators aren’t actually defined anywhere. He asked for
clarification. Larry supplied some, and, after some prompting from Stéphane
Payrard declared that Perl 6’s would do lazy evaluation by default, would
guarantee some kind left to right evaluation, and that, if all else failed the
** steamroller would make things eager again.
http://groups.google.com/groups?threadm=000901c5e6c5$cbce7c20$841d4447@JoeGottman1
Acknowledgements, apologies and everything else
Matt Fowles was on holiday last week, and didn’t have time to write a summary. Hopefully he was having a fabulous time instead. We hope to be back on a weekly schedule from next week.
Thanks to the people who contacted me last week. I am still looking for work, but I also have some leads to follow up on, which is a start. The summaries are still looking for a sponsor though; if you’re interested drop me or Matt a line, we’d be delighted to hear from you.
Help Chip
The usual coda
If you find these summaries useful or enjoyable, please consider contributing to the Perl Foundation to help support the development of Perl.
http://donate.perl-foundation.org/—The Perl Foundation
http://dev.perl.org/perl6/—Perl 6 Development site
Check out my website, it’s lovely.
Vaguely pretty photos by me can be found at:
Back from 'Dam
Well, I’m back from EuroOSCON, which was a pile of fun. I spent most of my time on the ‘hallway track’, occasionally dropping in on interesting talks and keynotes, but mostly just hanging around with interesting people. I took a pile of photos and still have a couple of rolls of film left to develop now I’m back home.
If you’re in Amsterdam and need a professional lab, allow me to recommend Kleurgamma. It’s always a little nerveracking taking negatives to a new lab, but they were exemplary. And they had some fantastic images hanging in their lobby…
Expect more articles about/inspired by the conference soonish.
Packing for EuroOSCON
My new combined laptop and camera bag arrived yesterday, a Crumpler December Quarter. It’s a little snug for my 17” Powerbook, but it’ll serve. The question now is, what cameras do I pack?
It turns out that Amsterdam is possessed of a pro lab that can do a 4 hour turnaround on black and white dev+contacts (and presumably not much longer for dev+scan).
So, do I take advantage of this, ditch the D100 and come armed solely with my F100, a couple of really nice lenses and a pile of Neopan 1600?
I think I do. I don’t want to start having to use the flash when I’m shooting indoors and, even with the kind of fast lenses I have to hand, I don’t trust the D100 over about 200 ISO so it’ll pretty much require flash assistance. Meanwhile, I know and trust Neopan 1600, it’s been my default film pretty much since I started taking photos and, whilst it may be grainy, it’s good grain. It worked for EuroFoo after all.
Looks like it’s decided. I’ll be the guy with the big camera who isn’t using flash.
Older posts: 1 2
