1

我对clojure非常陌生,所以我想用java编写代码。

我所拥有的是这个当前的代码。但似乎抛出 CompilerException java.lang.RuntimeException: Can't take value of a macro: #'clojure.core/->, compile:(NO_SOURCE_PATH:2)

此外,它似乎只实例化一个对象

(defrecord Learning [Name Age Gender])
  (def person 
    (apply -> Learning
           (clojure.string/split
             "Jon,12,Male", #",")
           )
    )

但是,我想做的是用java编写代码。例如在Java中,我们会有一个像

Public class Person {
Private int age;
Private String Gender;
Private String Name;

Person(String Name, String gender, int age)
{
this.name = Name;
this.age = age;
this.Gender = gender;
}
}

To Instantiate an instance of this class we would have a line like 

Person Jon = new Person(Jon, Male, 12); 

我将如何在clojure中做到这一点?

我有这个

(defn update [x]
  (def person 
    (apply ->Learning
           (clojure.string/split
             x, #",")
           )
    )
)

但它说它是一个畸形的表达。我想做的就像在java中创建一个构造函数。

4

1 回答 1

2

为避免编译器错误,只需删除和之间->的空格Lerning

(def person (apply ->Learning
                   (clojure.string/split
                    "Jon,12,Male", #",")))

它会起作用的

person
-> Learning{:Name "Jon", :Age "12", :Gender "Male"}
于 2013-01-01T04:15:24.147 回答