有谁知道Mysql的正则表达式是否支持unicode?我一直在做一些研究,大多数博客等似乎表明存在问题或者不支持.我想知道最好是使用LIKE进行unicode模式匹配和regexp进行ASCII增强模式匹配吗?
我喜欢能够在字符串的开头或结尾搜索匹配的想法,但如果regexp不支持unicode,那么如果我的文本是unicode则可能很难.
我们经常需要传递代码上下文信息,例如执行操作的用户.我们将此上下文用于授权检查等各种事务.在这些情况下,隐含值可以证明对减少锅炉板代码非常有用.
假设我们传递了一个简单的执行上下文: case class EC(initiatingUser:User)
我们可以有方便的守卫:
def onlyAdmins(f: => T)(implicit context:EC) = context match{
case EC(u) if(u.roles.contain(Role.ADMIN)) => f
case _ => throw new UnauthorizedException("Only admins can perform this action")
}
val result = onlyAdmins{
//do something adminy
}
Run Code Online (Sandbox Code Playgroud)
我最近发现自己需要在与Akka演员合作时这样做,但他们使用模式匹配,我还没有找到一个很好的方法来使implicits与提取器一起工作.
首先,您需要使用每个命令传递上下文,但这很简单:
case class DeleteCommand(entityId:Long)(implicit executionContext:EC)
//note that you need to overwrite unapply to extract that context
Run Code Online (Sandbox Code Playgroud)
但是接收函数看起来像这样:
class MyActor extends Actor{
def receive = {
case DeleteCommand(entityId, context) => {
implicit val c = context
sender ! onlyAdmins{
//do something …Run Code Online (Sandbox Code Playgroud) 在HaskellWiki的Do notation被认为有害,部分有用的应用程序,我发现:
应该提到的是,你有时会承担起写无聊事情的负担.
例如
Run Code Online (Sandbox Code Playgroud)getRight :: Either a b -> Maybe b getRight y = do Right x <- y return x一个
case关于y的包括,要求如果y是不是一种权利(即左)失败,并且因此恢复在这种情况下没有.
在模式不匹配上调用fail(Nothing)听起来很有趣,所以我想尝试一下.但是,语法看起来不对 - 我们不是Eithermonad,所以我们如何从中提取任何东西y?
事实上,我试过,它给了我" 无法匹配类型'要么'与'可能''.所以让我们使用正确的模式匹配器,let在这里:
getRight y = do { let (Right x) = y; return x }
Run Code Online (Sandbox Code Playgroud)
这给了我一个语法错误" 输入错误解析}} ".不是我理解为什么这不起作用,而是让我们用多行符号写出来:
getRight y = do
let (Right x) = y
return x
Run Code Online (Sandbox Code Playgroud)
啊,这似乎工作 - 至少解析.然而:
*Main> getRight …Run Code Online (Sandbox Code Playgroud) 如果我们有一个数组
array = [1, 1, 0, 0, 2, 3, 0, 0, 0, 3, 3, 3 ]
Run Code Online (Sandbox Code Playgroud)
我们如何识别给定数字的运行(具有相同值的连续数量)?举例:
run_pattern_for(array, 0) -> 2
run_pattern_for(array, 3) -> 1
run_pattern_for(array, 1) -> 1
run_pattern_for(array, 2) -> 0
Run Code Online (Sandbox Code Playgroud)
没有2的运行,因为没有两个连续的显示.有一次运行3,因为只有一个将树作为连续数字显示.
我在使用2个可选路径从图表中选择数据时遇到问题.假设节点A,B,C,其中A与B和C具有可选关系.
如果我查询
match (a:A) where a.xx = XX optional match (a:A)-->(b:B) return ...
Run Code Online (Sandbox Code Playgroud)
要么
match (a:A) where a.xx = XX optional match (a:A)-->(c:C) return ...
Run Code Online (Sandbox Code Playgroud)
一切都按预期工作.
如果我结合2:
match (a:A) where a.xx = XX
optional match (a:A)-->(b:B)
optional match (a:A)-->(c:C)
return ...
Run Code Online (Sandbox Code Playgroud)
然后我只得到(经过长时间的查询时间)一个未知的错误.
返回从a,b,c中选择属性,并使用限制来限制返回的数据量.是否不可能有多个可选匹配?
更新: 当我将查询更改为
match (a1:A) where a.xx = XX
optional match (a2:A)-->(b:B) where a2.uid = a1.uid
optional match (a3:A)-->(c:C) where a3.uid = a1.uid
return ...
Run Code Online (Sandbox Code Playgroud)
如果uid是唯一的索引id,则查询返回所需的结果.但它的运行速度非常慢(如果uid是索引,则为~60秒,如果uid具有唯一约束,则为〜40s)数据集不是我称之为巨大的数据集:6500,b 86和c 90000条目.
我倾向于在终端中反复检查我的程序,同时在我选择的编辑器中修改它们以获得实时反馈.我通常会运行类似于:watch -d -n 1 "ghc -fno-code NoIncompletePM.hs".
不幸的是no-code,我用来避免一次又一次编译我不关心的代码的标志似乎与那个不相容warn-incomplete-patterns.例如,这个程序:
{-# OPTIONS -Wall #-}
module NoIncompletePM where
argh :: Bool -> Bool
argh True = True
Run Code Online (Sandbox Code Playgroud)
我从来没有得到任何argh错过案例的警告False.可以通过删除no-code标志并添加标志来获取所有这些警告force-recomp(以便每次都显示警告,而不仅仅是第一次编译警告)但我确实想避免编译此代码...
我在手册中找不到任何描述这些不兼容的内容,所以我猜这是一个意想不到的行为,或者我做错了什么.有线索吗?
在Haskell(和各种其他函数式编程语言)中,模式匹配可用于分配列表的特定元素,同时丢弃其他元素:
Prelude> let [x, _, z] = "abc"
Prelude> x
'a'
Prelude> [z, x]
"ca"
Run Code Online (Sandbox Code Playgroud)
请注意,' _'不是变量,并且未分配任何内容:
Prelude> _
<interactive>:5:1: Pattern syntax in expression context: _
Run Code Online (Sandbox Code Playgroud)
对于用Perl编写的Irssi脚本,我想做类似的事情并丢弃' '的第二个元素@_(即不将它分配给任何东西):
my ($message, _, $windowItem) = @_;
Run Code Online (Sandbox Code Playgroud)
这失败并显示错误消息:" Can't declare constant item in "my" at [...]overlength_filter.pl line 17, near ") =""
那么这个下划线通配符的Perl等价物是什么?
在F#中,我可以在语法中的各个位置使用模式匹配.
例如:
// Given this type...
type SingleCaseUnion = | SingleCaseUnion of int
/// ...I can do this:
let destructureInFunc (SingleCaseUnion n) =
printfn "%d" n
// ...and this:
type DestructureInMethod() =
member t.M(SingleCaseUnion n) =
printfn "%d" n
Run Code Online (Sandbox Code Playgroud)
但我无法弄清楚如何做到这一点:
type DestructureInCtor(SingleCaseUnion n) =
do printfn "%d" n
// type DestructureInCtor(SingleCaseUnion n) =
// ---------------------------------------^
//
// stdin(3,40): error FS0010: Unexpected identifier in type definition. Expected ')' or other token.
Run Code Online (Sandbox Code Playgroud)
我是否有错误的语法,或者F#不支持构造函数参数中的模式匹配?
我正在尝试匹配**String Newline String**函数Split 中的模式.
split::String -> [String]
split[] = []
split (x++'\n':xs) = [x]++split(xs)
Run Code Online (Sandbox Code Playgroud)
我收到这个错误:
Parse error in pattern: x ++ ('\n' : xs)
我在这做错了什么?
我知道还有其他方法可以达到相同的结果,但我想了解这种模式有什么问题.我对Haskell BTW很新.
pattern-matching ×10
haskell ×3
akka ×1
algorithm ×1
boyer-moore ×1
cypher ×1
do-notation ×1
f# ×1
implicit ×1
mysql ×1
neo4j ×1
perl ×1
regex ×1
ruby ×1
scala ×1
typechecking ×1
unicode ×1