Wow, Do We All Get a Language? #
We’re all having a lot of fun this year making lovely hybrid languages from Ruby syntax, be it Rails models, Rake tasks, Dwemthy. Martin Fowler is knocking out a series of articles on domain-specific languages and language workbenches, the IDE and BDUF equivalent. All the surrounding essays are really interesting, including his IDE-based metaprogramming example, which gives you an idea of how parsing and code generation is being organized into these crazy point-and-click apps with IntelliSense and stuff.
Readers of this site will particularly love the early slant of the workbench article, since he attempts to hack some C# code in meta fashion, but it can’t hold a candle to his YAML-ish custom syntax:
mapping SVCL dsl.ServiceCall 4-18: CustomerName 19-23: CustomerID 24-27 : CallTypeCode 28-35 : DateOfCallString mapping USGE dsl.Usage 4-8 : CustomerID 9-22: CustomerName 30-30: Cycle 31-36: ReadDate
And, better yet, his subtle retooling into Ruby code:
mapping('SVCL', ServiceCall) do extract 4..18, 'customer_name' extract 19..23, 'customer_ID' extract 24..27, 'call_type_code' extract 28..35, 'date_of_call_string' end mapping('USGE', Usage) do extract 9..22, 'customer_name' extract 4..8, 'customer_ID' extract 30..30, 'cycle' extract 31..36, 'read_date' end
I found it almost bewildering that he links to Chapter Six of the (Poignant) Guide in his discussion of Ruby metaprogramming. I mean the reference to Rails is natural, but I would hate for this cartoon book to gain credibility. He knows that I have sketches of my sister’s clones quenching their thirst with jackal’s blood, right??
MenTaLguY
You’ll have to live with it I think. Given time and proper exposure, quality inevitably becomes credibility.
And hey, you get to see it happening within your own lifetime, which not all artists do. Viva la Internet…
Jon Tirsen
Knowing Mr Fowler right I think he was just looking for an opportunity to link to the Poignant Guide.
hgs
“hate” seems a strong word here. What do you see happening to it? The Creative Commnons licencing suggest you want it to spread. There are parts of it which go straight past me because I don’t understand what they are for, but I think you will reach people with a different learning style from mine, as a result. This diversity is good. The explanations of topics have been handled well, so I think it should gain credibility. You might want to look at the Creating Passionate Users blog for more about usefully unconventional styles of teaching (relating to software, most often).
MenTaLguY
hgs: That is an awesome blog.
top poster
I have the feeling that this is a Tower of Babel moment.
We’re about to be scattered to the four winds, thrown down from our monolingual hubris. I won’t understand your code and you won’t understand mine. It going to be wonderful. Absolutely humbling.
spratz ve noolig grnl spoo! hatz sek sponli ktle foo?
hgs
Oh, and there’s this as well, about learning styles. Rest of that blog’s good too.
Peter
I agree that DSLs in Ruby are extremely fun (and surprisingly easy to implement). And as they say, variety is the spice of metaprogramming.
I recently made one for XHTML:
About a year ago I implemented an Assembler as a Ruby DSL , looked like this (yes, that’s actually ruby code ;)
hgs
I like the ruby assembler! May we see the code? I think some have done work on a Ruby FORTH , too: ratlast , for one.
slejfund
In Fowler’s example, on which object is ‘extract’? If someone would kindly provide an implementation of ‘mapping’ and ‘extract’, I’d appreciate it.
slejfund
figured it out: instance_eval.
Comments are closed for this entry.