我在Visual Studio的项目中使用了以前的StyleCop + FxCop.但现在我正在测试Visual Studio代码分析工具,它更容易集成到MSBuild中,我发现这个工具分析了FxCop和StyleCop的一些规则.
这个工具是FxCop和StyleCop的完全替代品还是只是实现了一些规则?
我可以在R中创建一个compose运算符:
`%c%` = function(x,y)function(...)x(y(...))
Run Code Online (Sandbox Code Playgroud)
要像这样使用:
> numericNull = is.null %c% numeric
> numericNull(myVec)
[2] TRUE FALSE
Run Code Online (Sandbox Code Playgroud)
但我想知道是否有一套官方功能来完成这类事情以及其他操作,比如在R.中进行currying.这主要是为了减少代码中括号,函数关键字等的数量.
我的咖喱功能:
> curry=function(...){
z1=z0=substitute(...);z1[1]=call("list");
function(...){do.call(as.character(z0[[1]]),
as.list(c(eval(z1),list(...))))}}
> p = curry(paste(collapse=""))
> p(letters[1:10])
[1] "abcdefghij"
Run Code Online (Sandbox Code Playgroud)
这对于例如聚合来说特别好:
> df = data.frame(l=sample(1:3,10,rep=TRUE), t=letters[1:10])
> aggregate(df$t,df["l"],curry(paste(collapse="")) %c% toupper)
l x
1 1 ADG
2 2 BCH
3 3 EFIJ
Run Code Online (Sandbox Code Playgroud)
我发现它比以下更优雅和可编辑:
> aggregate(df$t, df["l"], function(x)paste(collapse="",toupper(x)))
l x
1 1 ADG
2 2 BCH
3 3 EFIJ
Run Code Online (Sandbox Code Playgroud)
基本上我想知道 - 这已经为R做过吗?
假设我想知道F#是否具有类型的库函数
('T -> bool) -> 'T list -> int
Run Code Online (Sandbox Code Playgroud)
即,计算函数返回的列表中有多少项的内容.(或返回返回true的第一个项的索引)
在MSDN上的文档准备就绪之前,我曾经在MSR站点上使用F#的大列表.我可以在页面上搜索上面的文本,因为列出了类型.但是现在MSDN文档只列出了各个页面上的类型 - 模块页面是一个描述性文本.谷歌有点排序,但它无济于事
// compatible interfaces
('T -> bool) -> Seq<'T> -> int
// argument-swaps
Seq<'T> -> ('T -> bool) -> int
// type-variable names
('a -> bool) -> Seq<'a> -> int
// wrappers
('a -> bool) -> 'a list -> option<int>
// uncurried versions
('T -> bool) * 'T list -> int
// .NET generic syntax
('T -> bool) -> List<'T> -> int
// methods
List<'T> member : ('T …
Run Code Online (Sandbox Code Playgroud) 在Scheme中,我可以使用define-struct
二进制搜索树,但是你如何在Clojure中做到这一点?
clojure函数可以采用的参数数量似乎有限制.
定义具有20个以上参数的函数时,我收到以下内容:
#<CompilerException java.lang.RuntimeException: java.lang.RuntimeException: java.lang.Exception: Can't specify more than 20 params (NO_SOURCE_FILE:0) (NO_SOURCE_FILE:0)>
显然这可以避免,但我正在达到这个限制,将现有DSL的执行模型移植到clojure,并且我在我的DSL中有如下构造,通过宏扩展可以非常容易地映射到函数,除了这个限制:
(defAlias nn1 ((element ?e1) (element ?e2)) number
"@doc features of the elements are calculated for entry into
the first neural network, the result is the score computed by the latter"
(nn1-recall (nn1-feature00 ?e1 ?e2) (nn1-feature01 ?e1 ?e2) ... (nn1-feature89 ?e1 ?e2)))
Run Code Online (Sandbox Code Playgroud)
这是一个用于调用具有90个输入节点的神经网络的DSL语句.当然可以解决它,但想知道限制的来源.谢谢.
我是clojure的新手,并通过SICP学习.
我无法从SCIP 1.3.1中获得这段代码.
我错过了什么?
(defn sum [term a next b]
(if (> a b)
0
(+ (term a) (sum term (next a) next b))))
(defn sum-cubes-new [a b]
((sum cube a inc b)))
Run Code Online (Sandbox Code Playgroud)
这是错误信息:
java.lang.Integer cannot be cast to clojure.lang.IFn
[Thrown class java.lang.ClassCastException]
Restarts:
0: [ABORT] Return to SLIME's top level.
Backtrace:
0: user$sum_cubes_new__2868.invoke(summation.clj:33)
1: user$eval__2874.invoke(NO_SOURCE_FILE:1)
2: clojure.lang.Compiler.eval(Compiler.java:4642)
3: clojure.core$eval__5236.invoke(core.clj:2017)
4: swank.commands.basic$eval_region__910.invoke(basic.clj:40)
5: swank.commands.basic$eval_region__910.invoke(basic.clj:31)
6: swank.commands.basic$eval__930$listener_eval__932.invoke(basic.clj:54)
7: clojure.lang.Var.invoke(Var.java:359)
8: user$eval__2871.invoke(NO_SOURCE_FILE)
9: clojure.lang.Compiler.eval(Compiler.java:4642)
10: clojure.core$eval__5236.invoke(core.clj:2017)
11: swank.core$eval_in_emacs_package__458.invoke(core.clj:58)
12: swank.core$eval_for_emacs__536.invoke(core.clj:126)
13: clojure.lang.Var.invoke(Var.java:367) …
Run Code Online (Sandbox Code Playgroud) 我需要这种类型的二元组合器
(a -> Bool) -> (a -> Bool) -> a -> Bool
Run Code Online (Sandbox Code Playgroud)
或者可能
[a -> Bool] -> a -> Bool
Run Code Online (Sandbox Code Playgroud)
(虽然这只是第一个的foldr1,我通常只需要组合两个布尔函数.)
这些是内置的吗?
如果没有,实现很简单:
both f g x = f x && g x
either f g x = f x || g x
Run Code Online (Sandbox Code Playgroud)
也许
allF fs x = foldr (\ f b -> b && f x) True fs
anyF fs x = foldr (\ f b -> b || f x) False fs
Run Code Online (Sandbox Code Playgroud)
Hoogle什么都没有,但有时它的搜索没有正确概括.不知道这些是否是内置的?它们可以用现有的图书馆建造吗?
如果这些不是内置的,您可能会建议使用新名称,因为这些名称非常糟糕.其实这是最主要的原因,我希望他们是内置.
当我从Mac OS的Terminal.app启动Python时,python将编码识别为UTF-8:
$ python3.0
Python 3.0.1 (r301:69556, May 18 2009, 16:44:01)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.stdout.encoding
'UTF-8'
Run Code Online (Sandbox Code Playgroud)
这对python2.5也是一样的.
但在Emacs中,编码是US-ASCII.
Python 3.0.1 (r301:69556, May 18 2009, 16:44:01)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.stdout.encoding
'US-ASCII'
Run Code Online (Sandbox Code Playgroud)
如何使Emacs与Python通信以便sys.stdout知道使用UTF-8?
编辑:由于我没有编辑接受的答案的代表,这正是在Aquaemacs 1.6,Mac OS 10.5.6上对我有用的.
在python-mode-hook中,我添加了该行
(setenv "LANG" "en_GB.UTF-8")
Run Code Online (Sandbox Code Playgroud)
显然,Mac OS需要"UTF-8",而dfa说Ubuntu需要"UTF8".
另外,我必须通过执行Cx RET p然后输入两次"utf-8"来设置输入/输出编码.我应该知道如何永久地设置它. …
我正在测试一个名为extractions的函数,它可以在任何列表上运行.
extractions :: [a] -> [(a,[a])]
extractions [] = []
extractions l = extract l []
where extract [] _ = []
extract (x:xs) prev = (x, prev++xs) : extract xs (x : prev)
Run Code Online (Sandbox Code Playgroud)
我想测试它,例如,用
import Test.QuickCheck.Batch
prop_len l = length l == length (extractions l)
main = runTests "extractions" defOpt [run prop_len]
Run Code Online (Sandbox Code Playgroud)
但这不会编译; 我必须为run
或提供一个类型prop_len
,因为QuickCheck无法生成[a]
,它必须生成具体的东西.所以我选择了Int
:
main = runTests "extractions" defOpt [r prop_len]
where r = run :: ([Int] -> Bool) -> TestOptions …
Run Code Online (Sandbox Code Playgroud) 我从http://tasteofpowershell.blogspot.com/2009/02/get-childitem-dir-results-color-coded.html获得了这个彩色目录脚本:
function ls {
$regex_opts = ([System.Text.RegularExpressions.RegexOptions]::IgnoreCase -bor [System.Text.RegularExpressions.RegexOptions]::Compiled)
$fore = $Host.UI.RawUI.ForegroundColor
$compressed = New-Object System.Text.RegularExpressions.Regex('\.(zip|tar|gz|rar)$', $regex_opts)
$executable = New-Object System.Text.RegularExpressions.Regex('\.(exe|bat|cmd|ps1|psm1|vbs|rb|reg|dll|o|lib)$', $regex_opts)
$executable = New-Object System.Text.RegularExpressions.Regex('\.(exe|bat|cmd|ps1|psm1|vbs|rb|reg|dll|o|lib)$', $regex_opts)
$source = New-Object System.Text.RegularExpressions.Regex('\.(py|pl|cs|rb|h|cpp)$', $regex_opts)
$text = New-Object System.Text.RegularExpressions.Regex('\.(txt|cfg|conf|ini|csv|log|xml)$', $regex_opts)
Invoke-Expression ("Get-ChildItem $args") |
%{
if ($_.GetType().Name -eq 'DirectoryInfo') {
$Host.UI.RawUI.ForegroundColor = 'DarkCyan'
$_
$Host.UI.RawUI.ForegroundColor = $fore
} elseif ($compressed.IsMatch($_.Name)) {
$Host.UI.RawUI.ForegroundColor = 'Yellow'
$_
$Host.UI.RawUI.ForegroundColor = $fore
} elseif ($executable.IsMatch($_.Name)) {
$Host.UI.RawUI.ForegroundColor = 'Red'
$_
$Host.UI.RawUI.ForegroundColor = $fore
} elseif ($text.IsMatch($_.Name)) …
Run Code Online (Sandbox Code Playgroud)