如何在clojure中调用嵌套的模板化构造函数

时间:2012-09-25 09:39:58

标签: clojure

我想使用clojure来探索这个例子 - http://jscience.org/api/org/jscience/mathematics/function/package-summary.html

    // Defines two local variables (x, y).
    Variable<Complex> varX = new Variable.Local<Complex>("x");
    Variable<Complex> varY = new Variable.Local<Complex>("y");

    // f(x) = ix² + 2x + 1
    Polynomial<Complex> x = Polynomial.valueOf(Complex.ONE, varX);
    Polynomial<Complex> fx = x.pow(2).times(Complex.I).plus(
        x.times(Complex.valueOf(2, 0)).plus(Complex.ONE));
    System.out.println(fx);
    System.out.println(fx.pow(2));
    System.out.println(fx.differentiate(varX));
    System.out.println(fx.integrate(varY));
    System.out.println(fx.compose(fx));

    // Calculates expression.
    varX.set(Complex.valueOf(2, 3)); 
    System.out.println(fx.evaluate());

我如何构建varX

1 个答案:

答案 0 :(得分:3)

假设您已导入org.jscience.mathematics.function.Variable$Local

(let [v (Variable$Local. "x")]
  ...)

也就是说,在将Java代码移植到Clojure时,您可以忽略类型参数,例如<Complex>。请注意,Local等嵌套类与其$的封闭类分开。