Search code examples
c#f#quotationsnemerle

Quotation real usages


I faced with the 'quotation' term and I'm trying to figure out some real-life examples of usage of it. Ability of having AST for each code expression sounds awesome, but how to use it in real life?

Does anyone know such example?


Solution

  • I think quotations have quite different uses in F# and Nemerle. In F#, you don't use quotations to extend the F# language itself, but you use them to take an AST (data representation of code) of some program written in standard F#.

    In F#, this is done either by wrapping a piece of code in <@ ..F# code.. @>, or by adding a special attribtue to a function:

    [<ReflectedDefinition>]
    let foo () = 
      // body of a function (standard F# code)
    

    Robert already mentioned some uses of this mechanism - you can take the code and translate F# to SQL to query database, but there are several other uses. You can for example: