5 ms·
A good read for anyone just starting out with some of the more intricate parts of Ruby. I often think Ruby is unsurpassed for writing readable, English-like DS
by bshimmin 12y ago
A good read for anyone just starting out with some of the more intricate parts of Ruby.
I often think Ruby is unsurpassed for writing readable, English-like DSLs - perhaps because of the combination of the convenient lassitude of Ruby's syntax (not requiring brackets - in many cases - or semi-colons) and the dangerous power of its metaprogramming abilities. The only other language that perhaps comes close and immediately springs to mind, before I've had my first coffee of the day, is (appropriately) CoffeeScript. Any other takers?
- lennel 12y agoon the jvm i would say groovy is probably one of the better languages for dsl's. Gradle is a dsl and groovy has inbuilt Builder classes to help you in the creation of dsl's Clojure being a lisp is extremely powerful in this regard as well, but if you are programming in any lisp I would expect a fair amount of meta programming.
- 0xfaded 12y agoLanguages with expressive type systems, Haskell likely the most mainstream, allow for deep embedding of an DSL, such that the type system of your DSL can be embedded into the parent language. IMHO absence of static analysis is a huge downside of using an interpreted language. Having type safety in an embedded DSL can only be dreampt of in a language like ruby. http://tom.lokhorst.eu/2009/09/deeply-embedded-dsls http://tom.lokhorst.eu/2009/09/deeply-embedded-dsls
- sklogic 12y agoWhat does typing have to do with interpreted vs. compiled? Hugs is an interpreter. And it's not a problem to build typed eDSLs on top of an untyped core language - see Typed Racket or Shen for example.
- malisper 12y agoLisp provides a couple really powerful DSLs. Some of more easily understandable ones I can think of: Loop: http://www.gigamonkeys.com/book/loop-for-black-belts.html http://www.gigamonkeys.com/book/loop-for-black-belts.html Symbolic Manipulation: http://norvig.com/paip/macsymar.lisp http://norvig.com/paip/macsymar.lisp Generating HTML: http://allegroserve.sourceforge.net/aserve-dist/doc/htmlgen.html http://allegroserve.sourceforge.net/aserve-dist/doc/htmlgen....
- virtualwhys 12y ago> Any other takers? Well, obviously on the type safe DSL front nothing compares to Scala or Haskell. Groovy's MOP was a bit buggy/lacking when I was using it (this is as of 3 years ago mind you, not sure how Groovy MOP has evolved since then) but I recall Gradle and Spock being impressive DSLs, very natural/readable.
- vorg 12y ago> Spock being impressive DSLs, very natural/readable The Spock syntax isn't a DSL, it hacks the ossified restrictions of the Antlr 2 based Groovy syntax to pull off tricks like overloading the | operator to give the appearance of tables, and the break/continue labels via an AST plugin to replace function calls with sections, as in this oft-quoted example from their website: expect: Math.max(a, b) == c where: a | b | c 1 | 3 | 3 7 | 4 | 4 0 | 0 | 0
- sklogic 12y agoRuby eDSLs are not that interesting - they still force you to stick to the Ruby syntax, which can be counterproductive. The best way of implementing eDSLs is to extend the syntax of your core language, which is very easy for the languages based on PEG. See https://github.com/combinatorylogic/mbase https://github.com/combinatorylogic/mbase and https://github.com/combinatorylogic/clike https://github.com/combinatorylogic/clike for example of this approach.
- draegtun 12y agoThere is a list of (some) languages here - http://en.wikipedia.org/wiki/Dialecting http://en.wikipedia.org/wiki/Dialecting (NB. I would add Factor, Haskell, Io and Perl6 to that list) I personally love how easy it is to write lucid & robust dialects in Rebol. Some examples of Rebol dialects... * List comprehension - http://blog.revolucent.net/2009/04/dirt-simple-dsl-in-rebol.html http://blog.revolucent.net/2009/04/dirt-simple-dsl-in-rebol.... * Cron/scheduler - http://softinnov.org/rebol/scheduler.shtml http://softinnov.org/rebol/scheduler.shtml * Excel - http://www.robertmuench.ch/development/projects/excel/dialect_documentation/ http://www.robertmuench.ch/development/projects/excel/dialec... * PDF builder - http://www.colellachiara.com/soft/Misc/pdf-maker-doc.pdf http://www.colellachiara.com/soft/Misc/pdf-maker-doc.pdf * GUI example (written in Rebol 2 VID) - https://news.ycombinator.com/item?id=7070349 https://news.ycombinator.com/item?id=7070349 * And a small ditty that I left on Reddit comment just to show what can be done - http://www.reddit.com/r/programming/comments/1tw17i/rust_is_surprisingly_expressive/cedeswe http://www.reddit.com/r/programming/comments/1tw17i/rust_is_...
- bshimmin 12y agoGreat list. Thank you!