Morning Coffee 144

  • I finished Mass Effect last night. I definitely need to play thru that one again, though I’ll probably wait until the new Bring Down the Sky DLC ships next month.
  • Caps won again last night, improving to 20-10-4 since changing coaches at Thanksgiving. They’re now at 57 points, taking the lead in the SE division with a full game on Carolina, Atlanta and Florida. Still a ways to go – 27 games left in the regular season – and things are far from “sewn up” but we’re a damn sight better off than we were in November.
  • Speaking of a horserace, looks like Clinton and Obama are in one after Super Tuesday. Their estimated delegate counts are basically tied. On the other side of the aisle, McCain opened up what is probably insurmountable lead – even though he has the right-wing media stars and Christian leaders against him. Money quote of the day:

“The real story of the night, when you look at their rallies and their turn-out numbers, is that the Dems have two strong candidates either of whom could lead a united party to victory. Forget the gaseous platitudes: in Dem terms, their choice on Super Duper Tuesday was deciding which candidate was Super Duper and which was merely Super. Over on the GOP side, it was a choice between Weak & Divisive or Weaker & Unacceptable. Doesn’t bode well for November.”\

  • Charlie Calvert is starting a new series on the future of C#. First up: Dynamic Lookup. Probably most interesting is the news that the DLR “will be the infrastructure on which the C# team implements dynamic lookup”. Does this mean C# will target the DLR? Sure sounds like it. I think it’s a good addition, but I’m not a fan of the proposed syntax. (via Bitter Coder)
  • Brian McNamara saw me present @ LangNET and sent me a link to his blog. He’s building up a monadic parser combinator library in C# 3.0. This is basically the same concept that FParsec implements, though C#’s syntax is much less attractive than F#’s for this kind of code. However, Brian does a very good job explaining why monadic parser combinators are useful and making the idea accessible to the C# programmer (i.e. you don’t have to learn F# or Haskell to understand what he’s talking about). He also points to Luke Hoban’s C# 3.0 monadic parser implementation.

Morning Coffee 143

  • I’ve been sick for three days, hence the lack of posting around here.
  • As a Redskins fan, it’s hard to root for any other NFC East team. On the other hand, it sure was easy to root against the Patriots. Congrats to the Giants on their Super Bowl victory. Favorite headline: 18 and uh-oh!
  • Sounds like there’s cause for optimism regarding the writer’s strike. But is it already too late? Will the 9% drop in viewers ever come back? Personally, I think the studios have hastened their own irrelevance.
  • With last night’s win, the Caps are one game above .500. In and of itself, that’s nothing to be proud of – Coach Boudreau remarked when we reached .500 that the Caps had “officially reached mediocrity”. However, the Caps are the only team in the SE conference that’s above .500. If hockey used baseball standings, Carolina, Atlanta and Florida would each be 1/2 game back of the Caps. It’s going to be a fight to the finish.
  • In fairly big managed Ruby news, Wayne Kelly has decided to contribute to the IronRuby effort, effectively walking away from the Ruby.NET which helped get off the ground. One the one hand, obviously this is great for IronRuby. On the other hand, I liked the idea of multiple managed implementations of Ruby, so here’s hoping Ruby.NET doesn’t fade away.
  • Speaking of the DLR, I know I mentioned Martin Maly’s blog in my Lang.NET Morning Coffee Post, but I didn’t actually get to read his posts on targeting the DLR until I unexpectedly had several days off sick. If you are at all interested in writing your own language for the .NET platform: Go. Read. Now. You should also check out Tomas Restrepo’s blog, he has also started writing about targeting the DLR.
  • Larry O’Brien’s blog is currently offline, but he commented that he doubted my ToyScript F# parser would be more than 600 lines of code. Currently, the parser is clocking in at 287 lines of code plus about 50 more for the AST. It’s not done yet – see earlier statement about being sick – but I’m fixing bugs not writing additional code at this point. To be completely accurate, that’s 287 lines of FParsec code. It’s taken me a little bit to learn FParsec, but so far I’m pretty happy with it.
  • Scott Hanselman points to the new MS Deploy project, a tool for managing content and configuration on web servers. I’ve never understood why this wasn’t a standard part of IIS. It seems every hosting company I’ve used has rolled their own web-based management tool like DotNetPanel.
  • Oh yeah, Vista SP1 and Windows Server 2008 shipped Monday. Congrats!
  • I fired up Inside Xbox the other day, and there was a page about the new Disney Channel show “Phineas and Ferb“. Of course, with two kids under five, anything new on the Disney Channel is notable in my house. What made this blog-worthy is the fact that it’s directed and written by Dan Povenmire, who I knew from my USC days. I used to go see his band Keep Left and groan loudly at the bad puns in their song “PSA”. Dan, if you found this searching for yourself online: Awesome work, my kids love the show!

Morning Coffee 142 – Wishful Catchup Edition

  • After spending most of the last four days away from my desk, I was planning on a quiet day to catch up on a variety of things. Then I heard the oh-so-minor news that Microsoft is offering to buy Yahoo for almost $45 billion. Hasn’t been much reaction on the dev, architecture, politics and hockey-oriented blogs I read, but you can get a ton of reactions on TechMeme.
  • Lost is back. Finally. I stayed up late last night reading Lostpedia, catching up on Lost Missing Pieces and the Find 815 ARG.
  • Alex The Great had four goals and an assist in last night’s victory. Coughing up three goal lead and letting the Canadiens tie the game in the last 30 seconds isn’t encouraging, but a win is a win. The Caps are currently one game behind the SE leading Hurricanes and two games behind the current eight seed Rangers. Alex was named first star for January.
  • Ted Neward has a nice summary of Lang.NET by day: one, two and three. I wonder if my talk qualifies for the exception to Ted’s rule that “A blog is not a part of your presentation, and your presentation is not part of your blog”. I had 15 minutes to discuss something I’ve written about over ten posts  (so far).
  • John Lam points to the latest DLR hosting spec. I’m much more interested in the DLR code generator, but at least the hosting interface is documented.
  • Scott Hanselman has a nice post on fluent interfaces. Note to self, find out if Beautiful Soup works with IronPython.
  • I wonder if the VS Source Code Outliner PowerToy works with F#? (via Sam Gentile)
  • Chris Tavares has an extensive post Deconstructing ObjectBuilder? I’ve poked around inside OB before, but I’m really looking forward to Unity (also via Sam Gentile)
  • NVIDIA finally updated the drivers for the video card in my Tecra M4. That only took a year.

Morning Coffee 141 – Lang.NET ’08 Edition

header

I was hoping to blog my thoughts on Lang.NET as the event went along. Obviously, that didn’t happen, though I was pretty good about dumping links into my del.icio.us feed. The talks were all recorded, and should be up on the website in a week or two. Rather than provide a detailed summary of everything that happened, here are my highlights:

  • The coolest thing about conferences like this is what John Rose called “N3″ aka “Nerd-to-Nerd Networking”. It was great to meet in person, drink with and geek out with folks who’s blogs I read like Tomas Petricek, Wesner Moise and Larry O’Brien. Plus, I got to meet a bunch of other cool folks like Gilad Bracha, Stefan Wenig and Wez Furlong. That’s worth the price of admission (which was admittedly nothing) right there.
  • Coolest MSFT talk: Martin Maly “Targeting DLR”. I was wholly unaware that the DLR includes an entire compiler back end. Martin summarized the idea of DLR trees on his blog, but the short version is “you parse the language, DLR generates the code”. That’s pretty cool, and should dramatically lower the bar for language development. Of course, I want to write my parser in F#, so I’m going to port the DLR ToyScript sample to F#.
  • Runner-up, Coolest MSFT talk: Erik Meijer “Democratizing the Cloud with Volta”. Erik is a great speaker and he really set the tone of his session with the comment “Division by zero is the goal, not an error”. He was referring to an idea from The Change Function that user’s measure of success is a function of perceived crisis divided by perceived pain of adoption. Erik wants to drive that adoption pain to zero. It’s a laudable goal, but I remain unconvinced on Volta.
  • Coolest Non-MSFT talk: Gilad Bracha “Newspeak”. Newspeak is a new language from one of the co-authors of Java. It’s heavily smalltalk influenced, and runs on Squeak. He showed developing PEGs in Newspeak, and they were very compact and easy to read, easier even than F#. He calls them Executable grammar, and you can read his research paper or review his slides on the topic. Unfortunately, Newspeak isn’t generally available at this time.
  • Runner-up, Coolest Non-MSFT talk: Miguel de Icaza “Moonlight and Mono”. The talk was kinda all-over-the-place, but It’s great to see how far Mono has come. Second Life just started beta testing a Mono-based script runner for their LSL language (apparently, Mono breaks many LSL scripts because it runs them so fast). He also showed off Unity, a 3D game development tool, also running on Mono.
  • Resolver One is a product that bridges the gap between spreadsheets and applications, entirely written in IronPython (around 30,000 lines of app code and 110,000 lines of test code, all in IPy). Creating a spread-sheet based app development environment is one of those ideas that seems obvious in retrospect, at least to me. If you do any kind of complicated spreadsheet based analysis, you should check out their product.
  • If you’re a PowerShell user, you should check out PowerShell+. It’s a free console environment designed for PowerShell and a damn sight better than CMD.exe. If you’re not a PowerShell user, what the heck is wrong with you?
  • Other projects to take a deeper look at: C# Mixins and Cobra Language.
  • I thought my talk went pretty well. It’s was a 15 minute version of my Practical Parsing in F# series. Several folks were surprised I’ve been coding F# for less than a year.

Practical F# Parsing: Recursion and Predicate Functions

To prep for my Lang.NET talk, I went back and reviewed my PEG parser. One thing I was not happy with was that all the recursion was handled in a one-off manner. When I needed to match multiple characters in the comment rule, I wrote a special one-off function to recursively process the comment until it reached an EOL. When I needed to parse a series of ranges, characters or definitions, I wrote special one-off functions to handle that recursion. Obviously, that’s not the best approach. So, I wrote the following active pattern functions to handle recursion.

//ZOM == Zero Or More
let rec (|ZOM|) f input =
    match f input with
    | Some(i,input) ->
        let j,input = (|ZOM|) f input
        (i :: j, input)
    | None -> [], input

//OOM == One Or More
let (|OOM|_|) f input =
    match (|ZOM|) f input with
    | [], input -> None
    | v, input -> Some(v,input)

//ZOO == Zero Or One
let (|ZOO|) f input =
    match f input with
    | Some(i,input) -> Some(i), input
    | None -> None,input

With these functions at the ready, I can stop writing one-off recursion functions. Instead, I write a function that matches a single item, which I pass as an argument to one of the three functions above. For example, here is the original and new version of the top level Grammar function.

//Original version
let (|Grammar|_|) input =
    let rec ParseDefinitions dl input =
        match input with
        | Definition (d, input) -> ParseDefinitions (dl @ [d]) input
        | _ -> Some(dl, input)
    let (|OneOrMoreDefintions|_|) input =
        match input with
        | Definition (d, input) -> ParseDefinitions [d] input
        | _ -> None
    match input with
    | Spacing (OneOrMoreDefintions (dl, EndOfFile)) ->
          Some(List.to_array dl)
    | _ -> None

//New Version
let (|Grammar|_|) = function
    | Spacing (OOM (|Definition|_|) (dl, EndOfFile)) ->
          Some(List.to_array dl)
    | _ -> None

The new version is much shorter, because there’s already a function to match a single definition, which we can pass into OneOrMore (aka OOM). Note, when I pass an active pattern function as a parameter, I have to use it’s real name (with the pipes and parameters). Having to use the real name is pretty ugly, but F# need to be able to differentiate between using a function as an active pattern vs using it as a function parameter. If you could just call OOM Definition (dl, EndOfFile), would F# realize Definition is a parameter?

I also defined syntactic predicate functions. If you’ll recall, these syntactic predicates will try to match but automatically backtrack, returning success or failure depending on which function you called.

//FP == Failure Predicate
let (|FP|_|) f input =
    match f input with
    | Some(_) -> None
    | None -> Some(input)

//SP == Success Predicate
let (|SP|_|) f input =
    match f input with
    | Some(_) -> Some(input)
    | None -> None

To see this in action, here’s the original and updated Primary function. Only the first rule is relevant, so I’ve omitted the others.

//Original version
let (|Primary|_|) input =
    let (|NotLEFTARROW|_|) input =
        match input with
        | LEFTARROW (_) -> None
        | _ -> Some(input)
    match input with
    | Identifier (id, NotLEFTARROW (input)) ->
        Some(Primary.Identifier(id), input)
    //rest of function omitted for clarity

//new version
let (|Primary|_|) = function
    | Identifier (id, FP (|LEFTARROW|_|) (input)) ->
          Some(Primary.Identifier(id), input)
    //rest of function omitted for clarity

Instead of writing a special function to match “not left arrow”, I just pass the left arrow function as a parameter to Failure Predicate (aka FP). With these recursion and syntactic predicate functions, I was able to remove all the one-off recursion functions from my parser. (Note, I posted an updated version of PegParser on my SkyDrive so you can see this in action.)

These five functions significantly reduced the complexity of the code. Unfortunately, I’m not sure it’s much easier to read. The conciseness is offset IMO by the ugliness of using the active pattern’s true names. Also, I would have liked to use custom operators for these five functions, but operators aren’t allowed to be active pattern functions. Hopefully, that will change at some point in the future, though if we’re going to dream of better syntax, can we do something about all the parens? Personally, I’d love to be able to write the following:

//This doesn't work, but I can dream, can't I?
let (|Primary|_|) = function
    | Identifier (id) !!LEFTARROW (input) ->
        Some(Primary.Identifier(id), input)
    //rest of function omitted for clarity

let (|Grammar|_|) = function
    | Spacing ++Definition (dl) EndOfFile ->
        Some(List.to_array dl)
    | _ -> None

Note to self, talk to F# team members who come to LangNET about this…