maradydd: (fail)
... and I'm just too much of an idiot to see it, so maybe one of you smart people can help me.

I'm writing a parser for a context-sensitive grammar in Haskell (for a language that I didn't design). At the moment I'm using Happy but I'm completely open to using parsec, uuagc, whatever will get the job done. Here's my problem:

In which Meredith loses at Haskell )
maradydd: (Default)
I've sung the praises of Learn You a Haskell here before, but it wasn't until a few minutes ago that I discovered Learn You Some Erlang. Different authors, but very similar styles -- writer Frederic Trottier-Hebert asked Miran Lipovaca (who brought you LYAH) if he could do a spinoff, and Miran said "of course".

My favourite feature so far is the interspersing of "Don't drink too much Kool-Aid" sections throughout the text -- a handy reality check, especially for a language that's caught a lot of buzz recently (thanks, Facebook). Concurrency is rad, the actor model is the New Hotness, but that doesn't make everything else necessarily old and busted, and Trottier-Hebert is happy to tell that to you straight. Oh, and it's a lot more fun than reading the Ericsson docs, which is what I did back when I learned Erlang. If you're wondering what all the excitement is about, go learn you some Erlang and find out.

I also wonder if this is actually a new trend. What will be next? Learn You the Chomsky Hierarchy? Learn You All About Category Theory? I look forward to finding out.

(h/t [ profile] alexey_rom via Twitter)
maradydd: (Default)
I just wrote an attribute grammar for the general object-encoding rules. (Not all of BER; that's next. Just section 8.1 of X.690.) Unless sections 8.2 through 8.22 throw me a curveball, which it doesn't look like they will, QED. It's fully left-recursive and uses only synthesized attributes, for all your efficient parsing needs. Boo yah.

If anyone playing along at home wants to have a look, drop me a comment.

FWIW, attribute grammars are absurdly simple in Haskell; Happy supports them natively. (Attribute grammars are somewhat intractable in strictly-evaluated languages because if you have to use strict evaluation, the data dependency graph gets impractically large very quickly. Haskell, which uses lazy evaluation, doesn't have this problem. Every day I come to love this little language more and more. Oh, and I can do a multiple-entry-point approach to support CER and DER. Seriously, how cool is that?)

Don Knuth, Haskell Curry, Simon Peyton-Jones, Simon Marlow and Andy Gill are totally my heroes forever and ever.


Aug. 11th, 2009 02:44 am
maradydd: (Default)
Lobster bisque, amaretto and attribute grammars on a rainy night.
maradydd: (Default)
  • Maybe is the same thing as Kleene ? (the "zero or one" operator in regular expressions).
  • A typeclass is the same thing as an STL concept, but a typeclass actually means it.
  • instance means "We're going to make this data type an instance of this typeclass, and here's how."
Now if I can just get my head around monads, I'm set.
maradydd: (Default)
This is entirely my fault. Feel free to throw tomatoes, but no rocks please.

(To the tune of "The Wild Rover". Apologies to Dennis Ritchie and people who don't like folk music. Also, the scansion and end rhyme go to hell in the third verse; sorry about that.)

Oh I've been a C coder for many an age
And I've spent all my free time on pointers and rage
But I like tail recursion much better than FOR
So I never will be a C coder no more.

And it's (cons car cdr),
Mapcar and lambda -- no more
Will I be a C coder, no never, no more.

I saw Dennis Ritchie one night in a bar
He had typedef'd his wallet to pointer to char
At last call he went to pay up for his friends
But he had no bounds checking and fell off the end

And it's (cons car cdr),
Mapcar and lambda -- no more
Will I be a C coder, no never, no more.

I first watched in silence, but I had a Scheme
So I thunked down my Visa and a small trampoline
At first no one there was quite sure what they'd seen
But the girls saw my Sexp and came home with me.

And it's (cons car cdr),
Mapcar and lambda -- no more
Will I be a C coder, no never, no more.

Feel free to add new verses.
maradydd: (Default)
Suppose you're a bioinformaticist and you have a gapped multiple sequence alignment (that is, a bunch of similar protein sequences, with dots and dashes inserted to line them all up), and you want the unaligned sequences, i.e., without all those dots and dashes. (Suppose further that you're using Bio.AlignIO from BioPython, and thus your multiple sequence alignment is an object containing other objects.)

You could write some loops and use .replace() a lot, or you could do something like this:

[''.join([x.upper() for x in record.seq if x.isalpha()]) for record in inputAlignment.get_all_seqs()]

(I'm really not sure how to describe the feeling of satisfaction I get from replacing ~20 lines of code with a list comprehension like this, but it's definitely rewarding.)


maradydd: (Default)

September 2010

12131415 161718
26 27282930  


RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags