From: Phlip Date: 2007-08-16T03:19:44+09:00 Subject: Re: Where can I find eval rules for ruby? Daryoush Mehrtash wrote: > I am trying to understand Domain Specific Language implementation in Ruby, > there are lot of examples such as > http://www.infoq.com/articles/eval-options-in-ruby, but I can't find a > definitive guide on the interpreters rule for evaluating a line of DSL > String in instance_eval call. DSL is a state of mind, not a language inside a string inside a language. The state of mind is that you intend to write in one language style, inside another language. For example, Rake is a _light_ form of rule solver, so you can write it in a format paralleling a Makefile: task :rule_1 => [:rule_2, :rule_C] do evaluate_rule_1 end To write in a declarative mode, write object methods with store their commands in an engine, and then process the engine. Here's a little Flea script to draw a spiral: egg = startOvum(18, 45, 100) ax = egg.newRootAxiom('A') b = egg.newAxiom('B') ax.longer(6).right.color(1).gosub(b) b.tube.shorter(0.8).left.link(b) render egg The commands like longer, right, color, etc are turtle graphics describing a shape. render then outputs the shape. All the ActiveRecord association commands - has_many, belongs_to, etc - qualify as DSLs too. The goal is to give your user-programmer a clear but deep interface, so they can write the command they need, in the relevant context they need, and the engine on the inside hides the complexity. -- Phlip http://www.oreilly.com/catalog/9780596510657/ ^ assert_xpath http://tinyurl.com/yrc77g <-- assert_latest Model