quotations

Is there any built-in function for human-readable F# quotations?

点点圈 提交于 2019-12-19 08:17:57
问题 When quoting <@ 1 + 1 @> I want "1 + 1" instead of "Call (None, Int32 op_Addition[Int32,Int32,Int32](Int32, Int32), [Value (1), Value (1)])" 回答1: You'll have to write it yourself. See the F# quotations visualizer code as a guide for transforming the quotations abstract syntax tree. 回答2: I have implemented a quotation decompiler as part of a larger open source project Unquote. It can decompile many simple F# quoted expressions as single-line non-light syntax strings (see the project's home

Converting F# Quotations into LINQ Expressions

坚强是说给别人听的谎言 提交于 2019-12-19 05:54:27
问题 I can convert a quotation of type Expr<'a -> 'b> to a Linq expression via the following snippet: /// Converts a F# Expression to a LINQ Lambda let toLambda (exp:Expr) = let linq = exp.ToLinqExpression() :?> MethodCallExpression linq.Arguments.[0] :?> LambdaExpression /// Converts a Lambda quotation into a Linq Lamba Expression with 1 parameter let ToLinq (exp : Expr<'a -> 'b>) = let lambda = toLambda exp Expression.Lambda<Func<'a, 'b>>(lambda.Body, lambda.Parameters) Now I want to convert a

Extract string from between quotations

▼魔方 西西 提交于 2019-12-18 11:03:30
问题 I want to extract information from user-inputted text. Imagine I input the following: SetVariables "a" "b" "c" How would I extract information between the first set of quotations? Then the second? Then the third? 回答1: >>> import re >>> re.findall('"([^"]*)"', 'SetVariables "a" "b" "c" ') ['a', 'b', 'c'] 回答2: You could do a string.split() on it. If the string is formatted properly with the quotation marks (i.e. even number of quotation marks), every odd value in the list will contain an

Parametric LINQ query

浪尽此生 提交于 2019-12-18 06:29:07
问题 This is another take on accessing dynamic objects in F# There I'm using let y = x.Where(fun x -> x.City ="London").Select("new(City,Zip)") to parametrize the query and extract the necessary items. These would correspond to columns in an SQL query, and be represented by a property of the datacontext. This is the part that I would like to pass in as a parameter. type Northwind = ODataService<"http://services.odata.org/Northwind/Northwind.svc"> let db = Northwind.GetDataContext() let query2 =

How to extract citations from a text (PHP)?

白昼怎懂夜的黑 提交于 2019-12-12 13:45:18
问题 Hello! I would like to extract all citations from a text. Additionally, the name of the cited person should be extracted. DayLife does this very well. Example: “They think it’s ‘game over,’ ” one senior administration official said. The phrase They think it's 'game over' and the cited person one senior administration official should be extracted. Do you think that's possible? You can only distinguish between citations and words in quotes if you check whether there's a cited person mentioned.

F# match pattern for Expr<int>

点点圈 提交于 2019-12-11 09:40:08
问题 I try to find the correct pattern to match and run an Expr<int> using the below code: open System.Linq open Microsoft.FSharp.Quotations open Microsoft.FSharp.Quotations.Patterns let runSelectQuery (q:Expr<IQueryable<'T>>) = match q with | Application(Lambda(builder, Call(Some builder2, miRun, [Quote body])), queryObj) -> query.Run(Expr.Cast<Microsoft.FSharp.Linq.QuerySource<'T, IQueryable>>(body)) | _ -> failwith "Cannot run this query %s" (q.ToString()) let runCountQuery (q:Expr<int>) =

jQuery random blockquote

老子叫甜甜 提交于 2019-12-11 03:13:51
问题 I've spent the past 2 hours looking for and testing various solutions to this problem but to little success so I'm resigned to asking for help. I would like to build an array of quotes which each have citations and and a link, to be pulled at random. I don't need any thing more than for them to change upon page refresh. However, I have some pretty tasty CSS to style blockquote and cite. Here's some example HTML to illustrate how the content from the array would fit within a quote: <blockquote

F# code quotation invocation, performance, and run-time requirements

大城市里の小女人 提交于 2019-12-11 01:26:51
问题 Here are 4 deeply related questions about F# code quotations - How do I invoke an F# code quotation? Will it be invoked in a manner less efficient than if it were just a plain old F# lambda? to what degree? Will it require run-time support for advanced reflection or code-emitting functionality (which is often absent or prohibited from embedded platforms I am targeting)? 回答1: Quotations are just data, so you can potentially "invoke" them in whatever clever way you come up with. For instance,

How to Get the F# Name of a Module, Function, etc. From Quoted Expression Match

我的未来我决定 提交于 2019-12-10 14:53:14
问题 I continue to work on a printer for F# quoted expressions, it doesn't have to be perfect, but I'd like to see what is possible. The active patterns in Microsoft.FSharp.Quotations.Patterns and Microsoft.FSharp.Quotations.DerivedPatterns used for decomposing quoted expressions will typically provide MemberInfo instances when appropriate, these can be used to obtain the name of a property, function, etc. and their "declaring" type, such as a module or static class. The problem is, I only know

What are F# quotations?

只谈情不闲聊 提交于 2019-12-07 02:32:07
问题 What are "quotations" in F#, and what are they used for? 回答1: In short, a quotation is metadata that represents the code of a particular function or code snippet. http://fortysix-and-two.blogspot.com/2009/06/traversing-and-transforming-f.html 回答2: See http://msdn.microsoft.com/en-us/library/dd233212.aspx and possibly http://en.wikipedia.org/wiki/Homoiconicity If you want scenarios, I bet you can find some by looking at https://stackoverflow.com/questions/tagged/F%23+quotations 回答3: They are