From: Yehuda Katz Date: 2008-12-03T02:36:18+09:00 Subject: [ruby-core:20214] Proposal: deferred blocks ------=_Part_79024_24571266.1228239716260 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Several people have played around with solutions that use ParseTree or RubyParser to extract the contents of a lambda and perform certain operations. For instance, Article.select {|a| a.title =~ /Some title/ } would generate "select * from articles where title ~ 'Some title'" This requires access to the ParseTree at runtime, which requires converting a proc to a ParseTree at runtime. I've been toying with the idea of an explicit language feature, like lisp quoting, that would explicitly pass the ParseTree to the method called. Example: Article.select(defer {|a| a.title =~ /Some title/ }) class Article def self.select(sexp) # sexp is: s(:defer, s(:lasgn, :a), s(:match3, s(:lit, /Some title/), s(:call, s(:lvar, :a), :title, s(:arglist)))) end end I understand that this would require a more explicit definition of the parse tree, but it seems like UnifiedRuby has provided a viable starting point for that work. Is this a terrible idea? Has it already been proposed and rejected innumerable times? -- Yehuda Katz Developer | Engine Yard (ph) 718.877.1325 ------=_Part_79024_24571266.1228239716260 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Several people have played around with solutions that use ParseTree or RubyParser to extract the contents of a lambda and perform certain operations.

For instance,

Article.select {|a| a.title =~ /Some title/ }

would generate "select * from articles where title ~ 'Some title'"

This requires access to the ParseTree at runtime, which requires converting a proc to a ParseTree at runtime. I've been toying with the idea of an explicit language feature, like lisp quoting, that would explicitly pass the ParseTree to the method called.

Example:

Article.select(defer {|a| a.title =~ /Some title/ })

class Article
  def self.select(sexp)
    # sexp is: s(:defer, s(:lasgn, :a), s(:match3, s(:lit, /Some title/), s(:call, s(:lvar, :a), :title, s(:arglist))))
  end
end

I understand that this would require a more explicit definition of the parse tree, but it seems like UnifiedRuby has provided a viable starting point for that work.

Is this a terrible idea? Has it already been proposed and rejected innumerable times?

--
Yehuda Katz
Developer | Engine Yard
(ph) 718.877.1325
------=_Part_79024_24571266.1228239716260--