我正在寻找一个输出文本中所有引用的SimpleGrepSedPerlOrPythonOneLiner.
例1:
echo “HAL,” noted Frank, “said that everything was going extremely well.” | SimpleGrepSedPerlOrPythonOneLiner
Run Code Online (Sandbox Code Playgroud)
标准输出:
"HAL,"
"said that everything was going extremely well.”
Run Code Online (Sandbox Code Playgroud)
例2:
cat MicrosoftWindowsXPEula.txt | SimpleGrepSedPerlOrPythonOneLiner
Run Code Online (Sandbox Code Playgroud)
标准输出:
"EULA"
"Software"
"Workstation Computer"
"Device"
"DRM"
Run Code Online (Sandbox Code Playgroud)
等等
(链接到相应的文本).
这是我的代码片段:
Public Function convert(ByVal robert As String)
Try
robert = Replace(robert, "U", "A")
robert = Replace(robert, "\"", "A")
Run Code Online (Sandbox Code Playgroud)
我想用A替换"引用",但程序似乎没有认识到我在VB中使用转义字符的事实.有谁知道为什么?谢谢!
罗伯特
编辑rlbond86:这显然是Visual Basic代码.我更改了标题和文字以反映这一点.
我遇到了F#powerpack报价评估的问题.
open Microsoft.FSharp.Linq.QuotationEvaluation
let print x = System.Console.WriteLine(sprintf "%A" x)
type record = { x:int; y:int }
let val1 = { x = 1; y = 1; }
let val2 = { x = 1; y = 1; }
let result = val1 = val2
print result
let quote = <@ let value1 = { x = 1; y = 1; }
let value2 = { x = 1; y = 1; }
let result2 = value1 = value2
result2 …
Run Code Online (Sandbox Code Playgroud) 我正在为SQL写一个F#dsl(http://github.com/kolosy/furious).
select语句如下所示:
type person = {
personId: string
firstname: string
lastname: string
homeAddress: address
workAddress: address
altAddresses: address seq
}
and address = {
addressId: string
street1: string
zip: string
}
let (neighbor: person seq) =
db.Yield <@ Seq.filter (fun p -> p.homeAddress.zip = '60614') @>
Run Code Online (Sandbox Code Playgroud)
显而易见(而且很愚蠢)的问题是......如何对报价进行参数化?
如果我只是喜欢:
let z = "60614"
let (neighbor: person seq) =
db.Yield <@ Seq.filter (fun p -> p.homeAddress.zip = z) @>
Run Code Online (Sandbox Code Playgroud)
然后z
被解析为静态属性访问器(PropertyGet(None, String z, [])
).我需要一些东西让我只根据报价检索变量/ let绑定的值.想法?
我需要打印一个完全正确的字符串:
std::string("-I\"/path/to/dir\" ");
Run Code Online (Sandbox Code Playgroud)
基本上,我需要这样做,因为我使用C++代码生成C++代码.
我想通过ofstream编写上面的字符串,所以像
ofstream fout;
fout << the_string << endl;
Run Code Online (Sandbox Code Playgroud)
问题是我不能\\"
在字符串里面做.
最近,我学习了如何实现具有反引号功能的准引号,如printfQ
下面的代码所示:
main = do
let itemName = "apple"
price = 1.29
[printfQ| The price of #{itemName} is #{price}. |]
Run Code Online (Sandbox Code Playgroud)
准引号的成分字符串将被传递到quoteExp printfQ :: String -> ExpQ
. 所以我们要做的就是解析给定的String
,找到要嵌入的名称"itemName"
,"price"
应用varE . mkName
每个名称,并构建ExpQ
.
现在假设我想扩展它printfQ
以允许表达式嵌入,如下所示:
[printfQ| The price of #{itemNames !! i} is #{price + taxOf price}. |]
"itemNames !! i"
我可以编写检测两个字符串和 的解析器"price + taxOf price"
。但随后我需要一个更强版本的,这是一个将这些字符串转换为varE . mkName
的函数,将它们解释为引用所使用的命名空间的表达式。String -> ExpQ
ExpQ
printfQ
我的问题:是否有任何库函数可以将此字符串转换为 AST?有一些简单的方法可以做到这一点,还是我需要编写整个 …
我想知道你是否可以在F#中添加类似"null-safe"-operator的东西.我知道可能有计划在C#中为这样一个运营商提供下一个更大的版本.
如果没有办法实现这样的行为,是否有办法包装一个可能会抛出一个NullReferenceException
捕获异常并返回的块的语句null
.
我想到了类似的东西:
let sth = %% <@ someobject.method().another().andAnother() @>
Run Code Online (Sandbox Code Playgroud)
其中%%
是执行表达式并检查异常的自定义运算符.
我做的一个尝试是:
open Microsoft.FSharp.Quotations
open Microsoft.FSharp.Linq.QuotationEvaluation
let (~%%) (right:Expr) =
try
right.CompileUntyped()
right()
with
| ex -> null
Run Code Online (Sandbox Code Playgroud)
但这不符合我的要求(事实上它甚至没有编译:)
我通读了:
有没有人有想法如何优雅地为链式方法创建这样的单行try-catch?
f# exception-handling operator-overloading quotations nullreferenceexception
假设我有两个简单的类:
type BaseClass() =
abstract member PreStart : unit -> unit
default x.PreStart() =
printfn "Base class PreStart method"
type DerivedClass() as this =
inherit BaseClass()
override this.PreStart() =
// I want to pass the body from outside
()
Run Code Online (Sandbox Code Playgroud)
我想要做的是允许场景DerivedClass.PreStart
从外部传递方法的实现主体.当然我只能传递一个可以在PreStart
方法内部调用的函数,但这有一些与base.PreStart()
方法调用有关的缺点.我必须传递一个额外的参数来指示我想要在覆盖主体之前执行基本方法的任何内容,或者根本不需要.
我想做的是允许身体的定义:
let preStart = (fun (baseFn : unit->unit) ->
baseFn() // base class call before the overriden body
printfn "PreStart overriden"
baseFn() // base class call after the overriden body)
Run Code Online (Sandbox Code Playgroud)
在哪里baseFn()
调用基类方法.如果我们可以传递委托来base.PreStart …
我有一个类型提供程序,它给出了错误"将表达式拼接到引号文字时类型不匹配".
我提取下面的代码,以便在较小的上下文中重现该问题.
let f (s : string) : string = s //some dummy implementation
let t = ProvidedTypeDefinition(asm, ns, "Root", Some typeof<obj>)
let ctor = ProvidedConstructor(parameters = [],
InvokeCode = (fun args -> <@@ "root" :> obj @@>)) :> MemberInfo
let prop = ProvidedProperty(propertyName = "SomeProperty",
parameters = [],
propertyType = typeof<string>,
GetterCode = (fun args -> <@@ f %%(args.[0]) @@>)) :> MemberInfo
do t.AddMembers [ctor; prop]
t.SetBaseType typeof<obj>
Run Code Online (Sandbox Code Playgroud)
...当我使用类型提供者时
let root = Provided.Root()
let a = root.SomeProperty
Run Code Online (Sandbox Code Playgroud)
我收到错误:
错误:类型提供程序'typeproviders.providerpoc …
我在 f# 中开始使用微积分工具箱。学习 f# 和最终在我想到的其他项目中使用一些有用的东西一样重要。基本且不完整的代码是
namespace BradGoneSurfing.Symbolics
open Microsoft.FSharp.Quotations
open Microsoft.FSharp.Quotations.Patterns
open Microsoft.FSharp.Quotations.DerivedPatterns
open System
open Microsoft.FSharp.Reflection
open Microsoft.FSharp.Quotations
open FSharpx.Linq.QuotationEvaluation
open Microsoft.FSharp.Linq.RuntimeHelpers
module Calculus =
let rec der_impl param quotation =
let (|X|_|) input = if input = param then Some(X) else None
match quotation with
| SpecificCall <@ (*) @> (_,types,l::r::[]) ->
let dl = der_impl param l
let dr = der_impl param r
<@@ (%%dl:double) * (%%r:double) + (%%l:double) * (%%dr:double) @@>
| SpecificCall <@ Math.Sin @> …
Run Code Online (Sandbox Code Playgroud)