Is the .NET platform embracing quotation and macros?

If you read between the lines (even if you don't) in Don Syme's blog post (near the end) he talks about DLinq and the use of quotation, abstract syntax and stuff like that.

In the C# 3.0 spec the Expression trees (26.8) are slipped in right at the end with the promise of another specification to describe them.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

What are quotation and

What are quotation and macros in this context?

Last time I dealt with macros, they were just literal replacements in assembly or C. Not very interesting nowadays.

Quotation & macros

Quotation in this context is quoting of program code, as seen in various kinds of metaprogramming. The literal replacement macros in assembler and C are "dumb", just doing textual substitution without any real knowledge of the meaning of a macro, or the syntax or semantics of the code being substituted into. This seriously limits what can safely be done with them, and is why they're not very interesting.

When you quote code in languages like Scheme, OCaml's Camlp4, Template Haskell, MetaML, Nemerle, etc., the language recognizes the semantics of the quoted code, and during macro expansion can e.g. allow macros to interact safely with variables in the invoking code. The result is a much more integrated way to do metaprogramming than e.g. generating source code using text strings. It allows metaprogramming capabilities to be integrated into a program, rather than being treated as an entirely independent code generation phase.

LINQ

In this context, the general idea is that you pass a lambda expression to a function, e.g. "filter" and depending on its implementation it can either evaluate it (in that case it's JIT-compiled like any other code), or it can use its "ExpressionTree", something like an AST, and work directly on this, to e.g. transform it into an SQL-Query. Different uses, like transforming it into GLSL-GPU-Code or DSP-Code spring to my mind.

It's really a shame that most programmers just look at the spec and say "ah, inline SQL-statements, who needs it?"...

quoting and macros

Quoting is a technique whereby you can store an expression away for later evaluation or analysis. Say you were writing a system that evaluated arithmetic expressions in the same syntax of the language you were writing the program in. Example: Say that in your language (+ 5 6) evaluated to 11. You could store the (list of) symbols by quoting them. In lisp, the syntax to dothat is '(+ 5 6).


Ok, that's useless in this example, but say you later wanted to find out if any of the input expressions contained a six. That is impossible with the already evaluated expression, but simple if you store the quoted expression.


As for macros, on LtU, macros usually refer to these macros.


This kind of macro is very different from a macro in C, because instead of manipulating strings in a cut and paste fashion, these macros can manipulate code that is represented as (for example) a quoted list. Imagine the power of such a macro: (I'm heavily paraphrasing here)

int foo(int a, int b) {
  const int r;
  printf("stuff");
  r = 
  return a + b;
}

int bar(int a, int b) {
  return a + b;
}

macro transform_plus(function int(*f)(int, int)) {
  for each_statement in f {
    if( the statement involves the + operator)
      print("plus being used on %d and %d", plus_arg1, plus_arg2);
  }
}


It sucks that these things have the same name.

As for macros, on LtU,


As for macros, on LtU, macros usually refer to these macros.

I think we usally mean Scheme macors not Lisp macros ;-)