我有一个可能有不同换行样式的文本.我想用相同的换行符替换所有换行符'\ r \n','\n','\ r'(在本例中为\ r \n).
最快的方法是什么?我目前的解决方案看起来像这样的方式很糟糕:
$sNicetext = str_replace("\r\n",'%%%%somthing%%%%', $sNicetext);
$sNicetext = str_replace(array("\r","\n"),array("\r\n","\r\n"), $sNicetext);
$sNicetext = str_replace('%%%%somthing%%%%',"\r\n", $sNicetext);
Run Code Online (Sandbox Code Playgroud)
问题是您无法通过一次替换来执行此操作,因为\ r \n将复制到\ r \n\r \n.
谢谢您的帮助!
我正在尝试使用指定为的算法实现unify函数
unify ? ? = idSubst
unify ? ? = update (?, ?) idSubst
unify ? (?1 ? ?2) =
if ? ? vars(?1 ? ?2) then
error ”Occurs check failure”
else
update (?, ?1 ? ?2) idSubst
unify (?1 ? ?2) ? = unify ? (?1 ? ?2)
unify (?1 ?1 ?2) (?3 ?2 ?4) = if ?1 == ?2 then
(subst s2) . s1
else
error ”not uni?able.”
where s1 = unify ?1 ?3
s2 = unify (subst …Run Code Online (Sandbox Code Playgroud) 假设我有以下规则:
unify('test', 'this is a test').
run :- write('Enter something: '),
read(X),
unify(X, Y),
write('The answer is '), write(Y).
Run Code Online (Sandbox Code Playgroud)
然后我运行如下:
?- ['unify.pl'].
% unify.pl compiled 0.00 sec, -48 bytes
true.
?- run.
Enter something: test.
The answer is this is a test
true.
?- run.
Enter something: 'test'.
The answer is this is a test
true.
Run Code Online (Sandbox Code Playgroud)
为什么SWI-Prolog的统一都test和'test'来unify('test', 'this is a test').?我在回答关于SO的Prolog问题时遇到了这个问题.虽然我能够回答这个人的问题,但我无法解释这个特殊的行为,我想知道是否有其他人可以.
我有一个包含数百个 STL 网格的文件夹,我想使用 flatten 命令将它们合并到 meshlab 中。
我使用的是常规 GUI,当我打开文件并选择所有这些 STL 文件时,如果我想“统一重复顶点”,系统会提示我输入每个文件。
由于我有数百个,这是不可接受的。有没有办法配置软件以将我的“是”应用于它打开的所有模型?
太棒了!
我想在两个新的向量中划分一个向量.
我们无法知道单个向量的长度是多少,但结果向量的总和必须等于参数.我试图捕获此属性如下:
partition : (a -> Bool) -> Vect (m+n) a -> (Vect m a, Vect n a)
partition p [] = ([], [])
partition p (x::xs)
= let (ys,zs) = partition p xs
in case p xs of
True => (x::ys, zs)
False => (ys, zs)
Run Code Online (Sandbox Code Playgroud)
但伊德里斯报告(指向"分区p []")在详细阐述Main.partition的左侧时:
Can't unify
Vect 0 a
with
Vect (m + n) a
Specifically:
Can't unify
0
with
plus m n
Run Code Online (Sandbox Code Playgroud)
为什么会这样?
对我来说,似乎很明显,如果"0 = m + n"而不是m = n = 0.如果说服伊德里斯这个怎么样?
关于我的考试,我有点不满意.我想通过手工应用统一算法找出这两个函数的类型:
map map
(\x -> x >>= (\y -> y))
Run Code Online (Sandbox Code Playgroud)
有人能指出我正确的方向吗?直到现在我唯一能找到的资源是维基百科条目,由于抽象程度很高,它并没有真正帮助我.
问候,谢谢.
我是Purescript(以及Haskell)的新手,我遇到了一个无法统一的错误.最初我有:
newtype Domain = Domain String
newtype Keyword = Keyword String
type Result = {
domain :: Domain,
occurred :: Boolean,
position :: Number,
quality :: Number
}
is_min_pos :: Maybe Result -> Maybe Result -> Maybe Result
is_min_pos Nothing Nothing = Nothing
is_min_pos Nothing y = y
is_min_pos x Nothing = x
is_min_pos x y = if y.position < x.position then y else x
Run Code Online (Sandbox Code Playgroud)
这给了我错误
Cannot unify type
Prim.Object
with type
Data.Maybe.Maybe
Run Code Online (Sandbox Code Playgroud)
我以为是因为期待x和y是Maybe Record类型.所以要明确我将代码改为,按类型进行模式匹配.
data Result = Result { …Run Code Online (Sandbox Code Playgroud) I have a dataset like this:
a1 <- c("a","a","a", "b", "c", "c", "d", "d", "d", "d")
b1 <- c(7, 7, 7,5, 4, 4, 3, 3, 3, 3)
c1 <- c("A","B", "C", "D", "E", "F", "B", "C", "EE", "F")
m1 <- data.frame(a1, b1, c1)
Run Code Online (Sandbox Code Playgroud)
my expected result is a dataset like this:
a <- c("a","b", "c", "d")
b <- c(7, 5, 4, 3)
c <- c("ABc","D", "EF", "BCEEF")
m <- data.frame(a, b, c)
Run Code Online (Sandbox Code Playgroud)
I try this code but it doesn't work: …
unify ×8
haskell ×2
idris ×1
iso-prolog ×1
meshlab ×1
newline ×1
php ×1
prolog ×1
purescript ×1
r ×1
replace ×1
types ×1
unification ×1
vertices ×1