tags:

views:

268

answers:

2

I hope I haven't missed something obvious, but I've been playing with F# expressions and I want to evaluate quoted expressions on the fly. For example, I want write something like this:

let x = <@ 2 * 5 @>
let y = transform x // replaces op_Multiply with op_Addition, or <@ 2 + 5 @>
let z = eval y // dynamically evaluates y, returns 7

Is there a built-in F# method which can evaluate quoted expressions, or do I have to write my own?

A: 

I think the quotations has got a .eval()-method.

Dario
+7  A: 

No, there's no built-in way to compile F# quotations. With the PowerPack LINQ you can convert SOME quotations to .NET System.Linq.Expressions.Expression, and use that to compile them.

Quotations were made to allow other interpretations of code, such as targeting SQL or a GPU card.

However, in posts on hubfs, it's been hinted at that this is a common request and will be looked at.

MichaelGG