DIP 50 - AST macros

Jacob Carlborg doob at me.com
Wed Nov 13 00:26:51 PST 2013


On 2013-11-12 17:14, John Colvin wrote:

> oh, I see. Would AST macros really be enough to make this work in D?
> "Arbitrary code" is a huge feature space in D, including much that
> doesn't map well to anything outside of a relatively low-level language,
> let alone SQL.
> I can see it quickly becoming a nightmare that would be worse than just
> issuing the predicate as an sql string or some generic equivalent.

Person.where(e => e.name == "John")

I'm thinking that we only need to convert the part that is prefixed 
with, in this example, "e". Any other code should be executed in the 
context of the caller. It should be possible to do this as well:

auto foo = "John";
auto result = Person.where(e => e.name == foo);

Which will result in the same SQL query.

I'm using a pluign to Ruby on Rails that does something similar but by 
overloading operators. The problem with this approach, in Ruby, is that 
you cannot overload operators like || and &&, so instead they overload | 
and & resulting in new problems like operator precedence. Example:

Person.where{ |e| (e.name == "John") & (e.address == "Main street") }

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list