hoodwink.d enhanced
RSS
2.0
XHTML
1.0

RedHanded

Wow, Do We All Get a Language? #

by why in inspect

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??

said on 18 Jun 2005 at 23:23

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…

said on 19 Jun 2005 at 22:48

Knowing Mr Fowler right I think he was just looking for an opportunity to link to the Poignant Guide.

said on 20 Jun 2005 at 08:19

“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).

said on 20 Jun 2005 at 08:25

hgs: That is an awesome blog.

said on 20 Jun 2005 at 12:09

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?

said on 20 Jun 2005 at 12:29

Oh, and there’s this as well, about learning styles. Rest of that blog’s good too.

said on 22 Jun 2005 at 12:00

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:

r = Ragex.new
r.html {
  head {
    title { "Hello Ragex" }
  }
  body {
    h1 { "Chunky" }
    em { "Bacon" }
    img "foxes.png", "I'm an alt tag." 
  } 
}
About a year ago I implemented an Assembler as a Ruby DSL , looked like this (yes, that’s actually ruby code ;)
label :start
ldi r2, 1
ldi r0, LCD_START
ldi r1, 0x1D    #"H" 
label :write
ld r3, r1
jzl :start, r3    #null terminated string
st r3, r0
add r0, r0, r2    #LCD+1
sub r1, r1, r2    #r1-1
jpl :write

said on 22 Jun 2005 at 17:51

I like the ruby assembler! May we see the code? I think some have done work on a Ruby FORTH , too: ratlast , for one.

said on 02 Sep 2005 at 07:57

In Fowler’s example, on which object is ‘extract’? If someone would kindly provide an implementation of ‘mapping’ and ‘extract’, I’d appreciate it.

said on 05 Sep 2005 at 10:51

figured it out: instance_eval.

Comments are closed for this entry.