Skip to content

Instantly share code, notes, and snippets.

@julienrf
Created April 20, 2011 12:11
Show Gist options
  • Save julienrf/931135 to your computer and use it in GitHub Desktop.
Save julienrf/931135 to your computer and use it in GitHub Desktop.
Is it possible to write more expressive things?
import tyco.compiler._
object MyWebsite extends tyco.Site {
for (page <- Content.allPages)
page.uri ==> Template.show(page)
for (file <- Path("stylesheets/*.scss"))
"/css/"+file.name ==> new TextFile(file) with Sass with CssMinifier
}
@engleek
Copy link

engleek commented May 23, 2011

Well the arrows are good, but if you want more expressive, you might have to write your own language.

@julienrf
Copy link
Author

That’s not only the arrows, but all the different ways to handle the different intents of the webmaster:

  • The for comprehension (for (page <- content.pages) { ... }) to retrieve the data of the webpages (e.g. from a database) ;
  • The way to chain file processors to compile sass files in minified CSS (new TextFile(file) with Sass with CssMinifier) ;

Given this website description you can generate the full website just by calling MyWebsite.compile() (cf my website).

Ok, there are still some noisy characters (namely braces or import statements) but I think the huge benefit of this compromise (an embedded DSL instead of a standalone own language) is that I didn’t need to implement a full compiler. I just wrote the missing delta between scala primitives and my DSL primitives, so that I can reuse the whole scala compiler infrastructure, its type system, etc. It gives me a lot of expression power as long as very high-level abstractions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment