artima.com — There's a whole world of language features that we sometimes miss out on as Rubyists, such as pattern matching, S-expressions, and external domain-specific languages. But the good news is that we can have them, too, as long as we're not afraid to steal a few things first.
May 24, 2006 View in Crawl 4
reverendpacoMay 24, 2006
Interesting. A few months ago, I tried stretching the boundaries of Ruby's meta-programming and eDSL capabilities by trying to emulate the Haskell/Erlang pattern-matching.The ideal scenario is where you can create your own 'def' syntax (a lisp-like macro)... something like: def_part fib( in ), :where => (in == 0) return 1end unfortunately I found (and this article confirms) that this bangs right up against the edges of Ruby's capabilities. No delayed-evaluation (aside from blocks) and no syntax-macros means that the syntax you create for things like multi-dispatch and pattern dispatch look way too heavily symbol based and string based. Now don't get me wrong. I love Ruby. But there is a psychology to believing you have found an embedded DSL. The reason Rails and Rake work so well is that they _look_ like what they are supposed to. This article shows you how to do these advanced programming techniques in Ruby, but the adoption will not happen until the psychological barrier is broken -- it looks too 'shoe-horned'. Remember, you can do Object Oriented in C with function pointers, etc. You can do double-dispatch in Java with horrendous Design Patterns.... But do you want to? Right now Ruby is perfect for creating embeddable _declarative_ DSLs.... because the class-level methods and the syntactic-sugar can look so much like what we expect a declarative language to be.Still, I loved that someone actually did this.
zitterbewegungMay 24, 2006
Has anyone ever heard of greenspun's 10th law??? Because once you add all of these features you have either CL with a few packages or <a class="user" href="http://www.scsh.net">http://www.scsh.net</a>
hoofartedMay 25, 2006
413x. I agree with everything you say. Just looking at the comments above, it seams like nobody understands what the article is about so I am confused about why there are so many diggs.
413xMay 25, 2006
@hoofarted: ok, this is strange indeed. :)