Search code examples
clojure

Return value in Clojure


How to describe a function in an interface, in whose signature the return type is the interface itself. I suppose that there is a way, to solve it, as it is in other languages.

(definterface Expression
  (^Number evaluate [data])
  (^Expression diff [diffVar]))
Syntax error (ClassNotFoundException) compiling deftype* at (expressionJava.clj:8:1).
java.lang.Expression

Full report at:
/var/folders/38/5xvf_2f13fbd4lfxg89f42x00000gn/T/clojure-7914023953805611339.edn

I'd tried to "declare Expreesion", but ain't help.


Solution

  • (definterface Expression
        (evaluate ^Number [data])
        (diff ^Expression [diffVar]))
    

    In Clojure, return type hints are metadata on the argument list, not on the function name.