如何在Clojure中使用definterface? [英] How to use definterface in Clojure?

查看:98
本文介绍了如何在Clojure中使用definterface?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Clojure 1.2.0似乎具有 definterface 形式,显然用于创建Java接口,并且有人建议使用它(例如,对此数字处理问题)。但是,我似乎找不到任何文档或如何使用它的大量示例。我是不是在正确的地方寻找东西,还是实际上它是一个早期功能,不应使用?我对展示 definterface 功能的文档或示例的指针感兴趣。

It seems that Clojure 1.2.0 has a definterface form, apparently for creating Java interfaces, and some people recommend using it (e.g. one answer to this number crunching question). However, I cannot seem to find any documentation or substantial examples of how to use it. Am I not looking in the right place, or is it actually such an early feature that it should not be used? I'm interested in pointers to documentation or examples demonstrating the features of definterface.

推荐答案

查看 gen-interface 的文档。

粗略形式为:

The rough form is:

(definterface Foo
  [bar [Arg1Type Arg2Type] ReturnType]
  [sideEffects [int] void]
  ...)

编辑::您是对的。该接口比 defprotocol 的接口更接近 gen-interface 的接口。

You are right. The interface is closer to that of defprotocol than that of gen-interface.

(definterface Foo
  [^int foo [x ^String y]]
  [^void bar [^ints is]])

这篇关于如何在Clojure中使用definterface?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆