我在SML上写这个函数.它应该列出可能的名字变体(我的名字是Victoria,所以V,Vic,Vicky等)并创建{altname1,middle,last},{alt2,middle,last}的记录.
所以这是我的代码:
fun similar_names (substits:, name) =
let
val {first=n1, second=n2, third=n3} = name
fun name_constructor (altnames:string list, acc) =
case altnames of
[] => acc
| a::aa => {first=a, second=n2, third=n3}::acc
in
name_constructor( get_substitutions2(substits, n1),name)
end
Run Code Online (Sandbox Code Playgroud)
get_substitutions2只会给出一个名字的所有可能变体的列表(即:字符串列表),并且它可以工作.
我得到的错误是:
a02.sml:65.2-65.58 Error: operator and operand don't agree [tycon mismatch]
operator domain: string list * {first:string, second:'Z, third:'Y} list
operand: string list * {first:string, second:'Z, third:'Y}
in expression:
name_constructor (get_substitutions2 (substits,n1),name)
Run Code Online (Sandbox Code Playgroud)
我不明白为什么它只在记录列表和记录之间进行.你能帮忙吗?
以下代码无法编译.我收到类型错误.我认为这将是更好的版本,因为它清楚地分离了两种不同的情况......该函数应该有助于确定有限状态机是否接受输入字.
import Text.Show.Functions
import qualified Data.Set as Set
import qualified Data.List as List
setTransition :: (Int -> Char -> [Int]) -> [Int] -> Char -> [Int]
setTransition delta [] sigma = []
setTransition delta xs@[x:xs'] sigma = foldl f [] xs
where f ys q = (delta q sigma) `List.union` ys
Run Code Online (Sandbox Code Playgroud)
然而,这(删除了模式匹配)会编译.谁能告诉我为什么?
import Text.Show.Functions
import qualified Data.Set as Set
import qualified Data.List as List
setTransition :: (Int -> Char -> [Int]) -> [Int] -> Char -> [Int]
setTransition delta [] …Run Code Online (Sandbox Code Playgroud) 我有一个创建mysql备份的脚本,文件最终被调用.
DB_name-M_D_Y.gz 所以例如 stackoverflow_users-04_10_2013.gz
现在我不知道文件的名称,只是模式.
我需要做的是调整脚本,在创建新备份之前,检查任何文件中的日期是否超过7天,如果有的话,还要做其他事情.
我知道如何做其他事情,但首先获取文件列表是困难的.
我不能只使用修改日期,因为其他脚本会触及文件,因此需要从文件名中读取日期.
那么,我如何获得文件列表?
当前日期:10 日 2013年4月
database zero-03_31_2013.gz #Older | Notice this one has spaces
database_one-04_01_2013.gz #Older
database_two-04_02_2013.gz #Older
database_three-04_03_2013.gz #Newer | Actually 7 days, but we want OLDER than!
database_four-04_04_2013.gz #Newer
database_five-04_05_2013.gz #Newer
dater.sh #Does not have the .gz extension | Not deleted
Run Code Online (Sandbox Code Playgroud)
Bash版本
matthew@play:~/test$ bash --version
GNU bash, version 4.2.37(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; …Run Code Online (Sandbox Code Playgroud) 如果Scala中有模式匹配(case),例如:
foo match {
case a: String => doSomething(a)
case f: Float => doSomethingElse(f)
case _ => ? // How does one determine what this was?
}
Run Code Online (Sandbox Code Playgroud)
有没有办法确定实际捕获的类型?
如果我的文本包含任何数组内容而不是"发短信"的话,我如何检查我的文本?
string text = "some text here";
string[] array1 = { "text", "here" };
string[] array2 = { "some", "other" };
Run Code Online (Sandbox Code Playgroud)
我在SO上找到了这个代码,我该怎样才能适应它?
string regexPattern = string.Format(@"\b{0}\b", Regex.Escape(yourWord));
if (Regex.IsMatch(yourString, regexPattern)) {
// word found
}
Run Code Online (Sandbox Code Playgroud)
正则表达式是这项工作的最佳方法吗?或者我应该使用foreach循环?
你能告诉我,我正在做错误的尝试使用正则表达式模式匹配吗?我有以下代码
val Pattern = "=".r
val Pattern(key, value) = "key=value"
Run Code Online (Sandbox Code Playgroud)
我在运行时得到以下异常
Exception in thread "main" scala.MatchError: key=value (of class java.lang.String)
Run Code Online (Sandbox Code Playgroud) 我继续学习F#模式匹配我的简单函数,如果参数是数字,则返回平方根,否则返回参数.我修改了一下它看起来如下.
let my_sqrt (o: obj) =
match o with
| :? float as d -> (sqrt d).ToString()
| _ as x -> x.ToString()
Run Code Online (Sandbox Code Playgroud)
它适用于我的目的,但如果我不想将返回值转换为字符串怎么办?如何返回"某个对象"然后在printfn "%A" (my_sqrt [| 1; 2; 3 |])构造中使用它?
有没有:
private static final String LUCENE_ESCAPE_CHARS = "[\\\\+\\-\\!\\(\\)\\:\\^\\]\\{\\}\\~\\*\\?]";
private static final Pattern LUCENE_PATTERN = Pattern.compile(LUCENE_ESCAPE_CHARS);
private static final String REPLACEMENT_STRING = "\\\\$0";
Run Code Online (Sandbox Code Playgroud)
并在诸如doGet()servlet之类的多线程环境中使用以下内容?
String escaped = LUCENE_PATTERN.matcher(query).replaceAll(REPLACEMENT_STRING);
Run Code Online (Sandbox Code Playgroud)
我主要担心的是现在增加额外的延迟(例如由于锁定)或者存在发生错误的情况.
combineb :: (Integer,Integer) -> [Integer] -> Integer
comnineb _ [] = 0
combineb x (l:ls) = l + (combineb x ls)
Run Code Online (Sandbox Code Playgroud)
程序错误:模式匹配失败:combineb(2,1)[]
你能帮帮我吗,为什么不[_]匹配(2,1)[]?
顺便说一句.我知道我实际上从未在这个功能中使用过第一个Paremter ......
我有一个包含字母和数字的字符串.此字符串还包含我要提取的日期.
例如: anv749dld95hd01/01/2012ncjf739dkcju
我想获得包含以下内容的新字符串: 01/01/2012
我唯一想到的就是使用它来分割它:str.Split('/')
这样我将获得一个数组并处理每个单元格 - 获取第一个单元格的两个最后一个字符,获取第二个单元格的值,然后从中获取前4个字符第三个细胞.
有没有更好的方法呢?