English 中文(简体)
在衣物中,使用除草剂和脱衣物会有什么错误?
原标题:What s wrong with this use of rest params with defprotocol and defrecord in Clojure?

下面在衣物中使用除草剂和脱衣物的残余物有什么错误?

(defprotocol prot
  (f [this] [this & rest]))

(defrecord rec []
  prot
  (f [this] "one arg")
  (f [this & rest] "more than one arg"))

(prn (f (rec.)))
; (prn (f (rec.) 5))
(prn (f (rec.) 5 6))
; (prn (f (rec.) 5 6 7))

以上编码印刷了我预期的产出:

"one arg"
"more than one arg"

但是,如果我不赞同其中一条评论的话,我可以得出以下例外:

Exception in thread "main" java.lang.IllegalArgumentException: No single method: f of interface: user.prot found for function: f of protocol: prot (bug.clj:10)
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:5376)
    at clojure.lang.Compiler.analyze(Compiler.java:5190)
    at clojure.lang.Compiler.analyze(Compiler.java:5151)
    at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3057)
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:5371)
    at clojure.lang.Compiler.analyze(Compiler.java:5190)
    at clojure.lang.Compiler.analyze(Compiler.java:5151)
    at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:4670)
    at clojure.lang.Compiler$FnMethod.parse(Compiler.java:4328)
    at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3173)
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:5367)
    at clojure.lang.Compiler.analyze(Compiler.java:5190)
    at clojure.lang.Compiler.eval(Compiler.java:5421)
    at clojure.lang.Compiler.load(Compiler.java:5857)
    at clojure.lang.RT.loadResourceScript(RT.java:340)
    at clojure.lang.RT.loadResourceScript(RT.java:327)
    at clojure.lang.RT.loadResourceScript(RT.java:319)
    at clojure.main$load_script.invoke(main.clj:220)
    at clojure.main$script_opt.invoke(main.clj:273)
    at clojure.main$main.doInvoke(main.clj:354)
    at clojure.lang.RestFn.invoke(RestFn.java:409)
    at clojure.lang.Var.invoke(Var.java:365)
    at clojure.lang.AFn.applyToHelper(AFn.java:163)
    at clojure.lang.Var.applyTo(Var.java:482)
    at clojure.main.main(main.java:37)
Caused by: java.lang.IllegalArgumentException: No single method: f of interface: user.prot found for function: f of protocol: prot
    at clojure.lang.Compiler$InvokeExpr.<init>(Compiler.java:2880)
    at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3063)
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:5371)
    ... 24 more

Why is this?

最佳回答

就我所知,议定书不支持理论论点。 可能发生的情况是,“和;”被视为一个论点象征,而不是衡量指标/清单理解。

问题回答

暂无回答




相关问题
How can I use DataTypes key as arguments

I have a macro that works as expected, but I want to make some changes to make it cleaner to use. #define FuncCreate(func_name, func, ...) int func_name(lua_State *ms) { func(__VA_ARGS__); ...

Nice way to pass parameters to PDO

Positional parameters become a nightmare when dealing with more than 3 or 4 parameters. Named parameters are verbose. I m thinking of doing this: query("SELECT * FROM users WHERE username = ", $...

Variable Argument Lists in C++/CLI

How do I create a function which accepts a variable argument list in C++/CLI? I am looking to create a function which forwards most of it s arguments to String::Format.

iterating over map and array simultaneously in a for loop

I am having some trouble creating a for loop within a constructor to iterate over a map and an array at the same time. Here, it is indicated that this cannot be done with an enhanced for loop. I have ...

热门标签