Info on Smalltalk DSLs or Metaprogramming...

Ramon Leon ramon.leon at allresnet.com
Fri Sep 1 23:09:34 UTC 2006


I'm headed out the door, so I'll respond to the rest later, but..

> Here's a Java html example (imagine your page is a subclass 
> of an html class--you override content() to set the page's content.)
> 
> public void content(){
> 
> 	header( title("My Document));
> 
> 	body(
> 		heading("My Document),
> 		text( currentDateAndTime())
> 	);
> }
> 
> This seems as good as the Lisp/Smalltalk examples. Admittedly 
> a C implementation would be much messier (we're limited to 
> functions, structs, global variables and macros), but it 
> still could be done.

While I'd consider this an embedded DSL, it's certainly not as good, because
the question arises what can go in a body?   How many args does body take,
nesting function calls like that won't be able to represent the same
hierarchical structure that html can represent, Lisp and Smalltalk can get
around this with anonymous functions, I'm not sure this can.

> html();
> 
> 	header();
> 		title("My Document");
> 	closeHeader();
> 
> 	body();
> 		heading("My Document");
> 		text(currentDateAndTime();
> 	closeBody();
> 
> closeHtml();
> 
> 
> Hmm. That's actually not too bad.
> 
> Admittedly, there are very few well written libraries for 
> Java/C/etc.  
> But that doesn't mean it can't (or shouldn't) be done.
> 
> -Rich-

And this is what you'd have to resort too, and also this actually is how
it's actually done in .Net, open a tag, close a tag, exactly the thing I was
saying made these languages bad at DSL's, they can't represent the semantics
of html with their native syntax, they're missing anonymous functions.
Ruby/Lisp/Smalltalk have a huge advantage here, they could express the html
in a hierarchical fashion, building a nice usable DSL, which I think neither
of these two are.





More information about the Squeak-dev mailing list