Closed ieugen closed 2 years ago
proxy+
doesn't understand protocols. You can instead reference the underlying interface, which would be <namespace>.ICsvTable
Sorry to bother but it does not work for me.
(ns ro.ieugen.inerface)
(defprotocol ICsvTable
"Some extra CSV table methods"
(isStream [this] "Return true if table is stream")
(getFieldTypes [this type-factory] "Returns the field types of this CSV table."))
(defn csv-table
[^Source source ^RelProtoDataType proto-row-type]
(let [row-type (atom nil)]
(proxy+ []
AbstractTable
(getRowType [this type-factory]
(get-row-type this source type-factory proto-row-type row-type proto-row-type))
ro.ieugen.interface.ICsvTable
(isStream [this] false)
(getFieldTypes
[this type-factory]
(println "hello")))))
clj꞉ro.ieugen.calcite-csv꞉>
; Evaluating file: calcite_csv.clj
; Syntax error macroexpanding proxy+ at (src/ro/ieugen/calcite_csv.clj:70:5).
; Could not resolve symbol
; Evaluation of file calcite_csv.clj failed: class clojure.lang.Compiler$CompilerException
If I take out the lines with and after ro.ieugen.interface.ICsvTable
it works ok.
Can the error message be improved ? It's not very helpful as is.
Perhaps when the proxy+ macro is expanded the protocol hasn't been defined yet. Try putting the protocol definition in a separate file.
Putting it in another file worked. I tried that but introduced a typo and I got confused in the process. Thank you again for confirming this.
I'm working on translating the Apache Calcite CSV example to Clojure. Calcite uses quite a few abstract classes. It was getting hard to re-implement all of that Java code with reify and proxy.
Thanks for writing this.
Hello,
I am trying to extend an abstract class and also implement custom methods (not belonging to an interface / abstract class). Is this possible?
I tried but it failed with error.
I also tried defining a protocol:
and I got this (cryptic) error message: