小编pro*_*eek的帖子

如何将默认参数值设置为BigInteger类型?

我需要一个具有BigInteger类型的构造函数的类.我想用这个代码将默认值设置为0,但是我遇到了编译错误.

public class Hello
{
    BigInteger X {get; set;}
    public Hello(BigInteger x = 0)
    {
        X = x;
    }
}

public class MyClass
{
    public static void RunSnippet()
    {
        var h = new Hello(); // Error <-- 
Run Code Online (Sandbox Code Playgroud)

怎么了?有没有办法将默认值设置为BigInteger参数?

c# biginteger

3
推荐指数
1
解决办法
2868
查看次数

为python安装stringtemplate3

我试图运行Python/cminus示例.从http://pypi.python.org/pypi/stringtemplate3/3.1,我为python安装了stringtemplate3 sudo python setup.py install.

当我运行以此代码开头的cminus.py时.

import sys
import antlr3
import stringtemplate3
Run Code Online (Sandbox Code Playgroud)

我有错误.

Traceback (most recent call last):
  File "cminus.py", line 3, in <module>
    import stringtemplate3
  File "/Library/Python/2.7/site-packages/stringtemplate3/__init__.py", line 14, in <module>
    from stringtemplate3.templates import *
  File "/Library/Python/2.7/site-packages/stringtemplate3/templates.py", line 35, in <module>
    import antlr
ImportError: No module named antlr
Run Code Online (Sandbox Code Playgroud)

看起来stringtemplate3使用的是antlr而不是antlr3.

我该如何解决这个问题?

python antlr stringtemplate

3
推荐指数
1
解决办法
1362
查看次数

C#中32位*32位数据的问题

我有这个代码,乘以32位*32位.

public static void RunSnippet()
{
    System.Int32 x, y;
    System.Int64 z;

    System.Random rand = new System.Random(DateTime.Now.Millisecond);
    for (int i = 0; i < 6; i++)
    {
        x = rand.Next(int.MinValue, int.MaxValue);
        y = rand.Next(int.MinValue, int.MaxValue);
        z = (x * y);
        Console.WriteLine("{0} * {1} = {2}", x, y, z);
    }
Run Code Online (Sandbox Code Playgroud)

但是,结果并不完全符合我的预期.

在此输入图像描述

这有什么问题?

.net c# math int

3
推荐指数
1
解决办法
162
查看次数

在C#中使用OfType过滤类型的对象

我有一个基类Base,以及继承它的A/B类.

public class Base
{
    int x;
}
public class A : Base
{
    int y;
}
public class B : Base
{
    int z;
}
Run Code Online (Sandbox Code Playgroud)

我尝试使用OfType来过滤我需要的唯一对象,如下所示:

public static void RunSnippet()
{
    Base xbase; A a; B b;
    IEnumerable<Base> list = new List<Base>() {xbase, a, b};
    Base f = list.OfType<A>; // I need to get only the object A
    Console.WriteLine(f);
}
Run Code Online (Sandbox Code Playgroud)

当我编译代码时,我收到此错误:

错误CS0428:无法将方法组'OfType'转换为非委托类型'Base'.你打算调用这个方法吗?

代码有什么问题?

c# linq oftype

3
推荐指数
1
解决办法
9560
查看次数

如何使用不同的工作区启动多个 Eclipse IDE?

我需要使用不同的工作区运行多个 eclipse。对于 Mac,我可以使用open -a Eclipse.app --args -data WORKSPACE. 当我执行时open -a Eclipse.app --args -data DIFFERENT_WORKSPACE,我只是重定向到现有的日食。

eclipse macos launcher

3
推荐指数
1
解决办法
3950
查看次数

对(const std :: pair &lt;_T1,_T2&gt;&)被隐式删除,因为默认定义的格式不正确错误:分配unique_ptr的映射时

我正在尝试使用一种方法设置一个unique_ptr的映射。

class A {
    map<int, unique_ptr<B>> x;
public:
    void setx(const map<int, unique_ptr<B>>& x) {this->x = x;} // <-- error
    ...
};
Run Code Online (Sandbox Code Playgroud)

但是,我得到了这个错误。

'constexpr std::pair<_T1, _T2>::pair(const std::pair<_T1, _T2>&) [with _T1 = const int; _T2 = std::unique_ptr<ContextSummary>]' is implicitly deleted because the default definition would be ill-formed:
Run Code Online (Sandbox Code Playgroud)

这项作业有什么问题?

c++ smart-pointers map variable-assignment

3
推荐指数
1
解决办法
2440
查看次数

在 python 中动态更改迭代器是否安全?

使用 python,我需要在迭代列表时动态添加列表中的成员:

i = [1,2,3,4,5]

for a in i:
    if a == 1:
        i.append(100)
    print a
Run Code Online (Sandbox Code Playgroud)

能保证正常工作吗?

python iteration

3
推荐指数
1
解决办法
1651
查看次数

Clojure中-toString与.toString的区别

继有关解释:gen-class的解剖学gen-class,我用leiningen得到的类文件.

  1. leon new pinger 创建一个项目.
  2. cd src并在其中mkdir some创建了一个Example.clj文件.
  3. 添加:aot [some.Example](或:aot :all)project.clj.

Example.clj如下:

(ns some.Example
  (:gen-class))

(defn -toString
  [this]
  "Hello, World!")
Run Code Online (Sandbox Code Playgroud)

然后我执行lein compile以获取target目录中的类.

然后,我正在执行此代码lein repl.

(-toString (some.Example.)) ; should return "Hello, World!"
Run Code Online (Sandbox Code Playgroud)

但是,我收到此错误消息.

CompilerException java.lang.RuntimeException: Unable to resolve symbol: 
-toString in this context, compiling:(/private/var/folders/nw/dmb7jh3d2hq89296z2gnntqm0000gn/T/form-
init7145760420048735997.clj:1:1) 
Run Code Online (Sandbox Code Playgroud)

.toString 工作良好.

user=> (.toString (some.Example.))
"Hello, World!"
Run Code Online (Sandbox Code Playgroud)

该网站解释说,我应该从两个相同的结果-toString.toString,但我只能用正确的结果 …

java clojure

3
推荐指数
1
解决办法
303
查看次数

没有运行Literate Haskell代码的(GHC.Base.Alternative Parser)错误的实例

我正在尝试在Graham Hutton的Haskell编程书(http://www.cs.nott.ac.uk/~gmh/book.html)中执行示例.尽管这些例子都是有文化的haskell,但我可以启动ghci来加载示例; 例如ghci cipher.lhs(http://www.cs.nott.ac.uk/~gmh/cipher.lhs):

GHCi, version 7.10.2: http://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Main             ( cipher.lhs, interpreted )
Ok, modules loaded: Main.
*Main> let2int 'a'
0
Run Code Online (Sandbox Code Playgroud)

但是有一些例子,由于ghci的变化,我有一些问题; 例如在第8章的Parsing.ls中,我有No instance for (Applicative ...)错误.

https://ghc.haskell.org/trac/ghc/wiki/Migration/7.10我得到了一些提示,通过添加一些代码来消除一些错误.

> instance Applicative Parser where
>    pure  = return
>    (<*>) = ap  -- defined in Control.Monad
>
> instance Functor Parser where
>    fmap  = liftM
>
> instance Alternative Parser where
>     (<|>) …
Run Code Online (Sandbox Code Playgroud)

haskell literate-programming

3
推荐指数
1
解决办法
1364
查看次数

Haskell中type和newtype之间的区别

从Haskell中的Programming(http://www.cs.nott.ac.uk/~gmh/book.html)一书中,解析器定义如下:

> type Parser a = String -> [(a,String)]
Run Code Online (Sandbox Code Playgroud)

但是,从示例代码(http://www.cs.nott.ac.uk/~gmh/Parsing.lhs)中,定义略有不同.

> newtype Parser a              =  P (String -> [(a,String)])
Run Code Online (Sandbox Code Playgroud)

我发现了这个页面的不同之处:https://wiki.haskell.org/Type#Type_and_newtype如下:

type引入了类型的同义词,并使用相同的数据构造函数.newtype引入了类型的重命名,并要求您提供新的构造函数.

这是我的问题:

  1. 对于新类型,为什么P(...)用于封装内容?
  2. 它需要为newtype提供新的构造函数,但我似乎没有从示例代码中找到一个.如何为newtype定义构造函数?可以不提供一个吗?

haskell types

3
推荐指数
1
解决办法
1122
查看次数