eigenclass logo
MAIN  Index  Search  Changes  PageRank  Login

The Neo-Rails controversy and a language generator

There's seemingly no end to the drivel coming from these Neo-Rails sects, or is it people pretending to be Java supporters posing as Railers?

Summing up, lgenerator.rb.

Here's a simple example (see the PostRailsMonkey Manifesto for a complex one):

require 'lgenerator'
gen = Generator.new do |g|
  # default non-terminal is main, can be set with    start :whatever
  main.is :hello, "\n", :ex1, "\n", :ex2
  hello.is "Hello, ", :somebody, "!"
  somebody.is "matz" | "world"     # basic disjunction

  ex1.is "This is a more ", ("complex " | "elaborate "), :example, "."
  example.is "example" | "test"

  ex2.define do
    is "Some simple sentence."
    is "Another, involving ", ["a more complex ", :exp] | "harder stuff ", "."
    is "Yet another possibility; each one is chosen with prob. 1/3."
  exp.is "expression" | "disjunction" | :example

puts gen.generate

#>> Hello, world!
#>> This is a more elaborate test.
#>> Yet another possibility; each one is chosen with prob. 1/3.

The language generator can handle recursive derivations and perform actions when a rule is followed. You can for instance make it remember the choice for a particular derivation and use it in another:

gen = Generator.new do |g|
  start :story
  story.is :intro, :sentence

  intro.is "I once met this guy, " | "I once ran into a guy named ", :name, ". "
  name.is {|e| e[:lastname] = e.expand("Bob" | "John" | "Joe") }
  thename.is {|e| e[:lastname]}

  sentence.is ["That guy (you know, ", :thename, ") told me that he "] |
              ["As it turns out, ", :thename, " "], :did_or_was_something, "\n",
              "I gave him a cold stare and ran away as fast as I could when I saw his ",
              :something_he_had, "."

  did_or_was_something.is "wanted to run his own ", :business, " business."
  business.is "chunky bacon" | "bug bbqing"
  something_he_had.is "his ", "hungry eyes" | "large knife"

puts gen.generate
# >> I once met this guy, John. That guy (you know, John) told me that he wanted to run his own chunky bacon business.
# >> I gave him a cold stare and ran away as fast as I could when I saw his his hungry eyes.

If you're into research papers, take a look at On the simulation of postmodernism and mental debility using recursive transition networks.

The next steps are obvious. Allow me to apologize in advance; this just has do be done.

I love you - toupeira (2007-03-29 (Thr) 13:00:13)

This absolutely rocks! I have no idea how to even start coding something like this...

mfp 2007-03-29 (Thr) 15:32:33

Actually, it pretty much writes itself once you start from the end using a simple grammar and implement as much as needed to make the generator work. The meta-programming techniques it requires are pretty basic (and quite rough, but it's OK for this toy), just method_missing and a few '|' methods placed strategically.

Pretty darn cool... - Chris (2007-03-29 (Thr) 14:54:27)

I gotta admit ... this is pretty darned cool. Great stuff.

An alternate take - Jeremy Voorhis (2007-04-06 (Fri) 15:46:10)

I just posted an alternate version of this language generator implemented with the Directed Ruby Programming gem. Although the output is similar, it is generated using evolutionary programming techniques.

Off topic question - Ruby on Rails Examples and code samples (2007-05-10 (Thr) 10:10:35)

Thanks for cool generator.

I was wondering what syntax highlighting plug in you are using? I really like to use it for Ruby on Rails examples which is a new ruby blog.

mfp 2007-05-10 (Thr) 10:36:09

I'm using Jamis Buck's "syntax" library, which makes syntax highlighting trivial; it takes about three lines of code, as shown in http://syntax.rubyforge.org/chapter-3.html#s1

Thank you - Ruby on Rails Examples and code samples (2007-05-10 (Thr) 11:35:49)

Thank you for answering.

I have to do comparison now to pick the best one.

Last modified:2007/03/29 03:51:52
Keyword(s):[blog] [ruby] [frontpage] [rails] [manifesto] [language] [generator] [snippet]
References:[The PostRailsMonkey Manifesto]