Article Discussion
If It's Not Nailed Down, Steal It
Summary: 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.
3 posts.
The ability to add new comments in this discussion is temporarily disabled.
Most recent reply: June 29, 2008 1:29 PM by Rich
    James
     
    Posts: 9 / Nickname: jbritt / Registered: March 24, 2003 4:10 PM
    If It's Not Nailed Down, Steal It
    May 22, 2006 10:00 PM      
    Topher Cyll explores Ruby implementations of assorted language features more typically found in Standard ML, Haskell, and Common Lisp.

    Read this Ruby Code & Stlye article to learn more.

    http://www.artima.com/rubycs/articles/patterns_sexp_dsls.html

    What did you think of Topher's article and examples?
    • topher
       
      Posts: 1 / Nickname: topher / Registered: January 30, 2006 6:37 AM
      "Stealing it back"
      June 2, 2006 9:27 AM      
      Richard Cook has great post about how to implement the Logo example from above in Common Lisp.

      http://i-need-closures.blogspot.com/2006/06/stealing-it-back.html

      Very cool!
      Topher
    • Rich
       
      Posts: 2 / Nickname: rdm / Registered: January 27, 2006 5:05 AM
      Re: If It's Not Nailed Down, Steal It
      June 27, 2008 10:23 PM      
      Very interesting article. I recently wrote RubyKif, a class that parses and emits the PowerLoom variant of KIF (Lisp-style predicate calculus).

      I used Treetop, so I'll be interested to compare the size and complexity of my solution to yours. I also map tokens to symbols, though I translate numbers and strings across. FWIW, I also translate comments to symbols.

      Although this is a simple and robust mapping, turning a KIF operator such as :<<=>> into the Ruby symbol :':<<=>>' does nothing to improve its readability (:-).

      http://cfcl.com/twiki/bin/view/Projects/Arti/Patterns/RubyKif_H2

      I've been wondering about stealing something else, BTW. The jQuery library has some really powerful mechanisms for dealing with DOM trees. Shouldn't Ruby be able to use the same mechanisms on random lists of lists?
      • Rich
         
        Posts: 2 / Nickname: rdm / Registered: January 27, 2006 5:05 AM
        Re: If It's Not Nailed Down, Steal It
        June 29, 2008 1:29 PM      
        Note: In order to make the parse_sexp example work, I had to require sexpressions, rather than sexp.


        PowerLoom's variant of KIF includes syntax that this library does not handle: exponential notation (eg, "1.2e3"), two kinds of comments (eg, ";...\n", '#|...|#'), and a slew of symbolic operators ranging from "=" to ":<<=>>".
        It may be a while before I am in a position to compare them on an equal footing...