The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Genetic Madlibs

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jeremy Voorhis

Posts: 212
Nickname: jvoorhis
Registered: Oct, 2005

Jeremy Voorhis is a Rubyist in northeast Ohio.
Genetic Madlibs Posted: Apr 6, 2007 3:19 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Jeremy Voorhis.
Original Post: Genetic Madlibs
Feed Title: JVoorhis
Feed URL: http://feeds.feedburner.com/jvoorhis
Feed Description: JVoorhis is a Rubyist in northeast Ohio. He rambles about Ruby on Rails, development practices, other frameworks such as Django, and on other days he is just full of snark.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Jeremy Voorhis
Latest Posts From JVoorhis

Advertisement

Inspired by the eigenclass language generator, I’ve thrown together an example of how it would be implemented with the Directed Ruby Programming library. Directed programming is an interesting hybrid of genetic programming and the recently discovered grammatical evolution technique which generates a program tree according to a grammar.

This example may not be very interesting for those familiar with evolutionary programming techniques, but it created a fun diversion, highlights how the DRP library is to be used, and shows a different solution for a language generator.


class DrpGenerator
  extend DRP::RuleEngine
  begin_rules
    def main() "#{hello}\n#{ex1}\n#{ex2}" end

    def hello() "Hello, #{somebody}!" end

    def somebody() "matz" end
    def somebody() "world" end

    def ex1() "This is a more #{adj1} #{example}." end

    def adj1() "complex" end
    def adj1() "elaborate" end

    def example() "example" end
    def example() "test" end

    def ex2() "Some simple sentence." end
    def ex2() "Another, involving harder stuff." end
    def ex2() "Another, involving a more complex #{exp}." end
    def ex2() "Yet another possibility; each one is chosen with an evolutionary algorithm." end

    def exp() "expression" end
    def exp() "disjunction" end
    def exp() example end
  end_rules
end

g = DrpGenerator.new
3.times { puts g.main }

Hello, matz!
This is a more elaborate example.
Another, involving a more complex disjunction.

Hello, world!
This is a more elaborate test.
Another, involving harder stuff.

Hello, world!
This is a more complex example.
Yet another possibility; each one is chosen with an evolutionary algorithm.

My DrpGenerator isn’t as readable or attractive as the eigenclass DSL, and multiple definitions of the same method will likely confuse most Rubyists at first glance, but makes it easy to see the underlying grammar.

Read: Genetic Madlibs

Topic: What Rails can learn from other frameworks Previous Topic   Next Topic Topic: XForms vs. Ruby on Rails

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use