在实现Clojure协议时,重载方法可以调用其重载的对应方吗?(When implementing a Clojure protocol, can an overloaded method call its overloaded counterpart?)
这是重载协议定义的一部分:
(defprotocol ClientProtocol (create-edge [this outV label inV] [this outV label inV data])
这是其实施的一部分:
(ns bulbs.neo4jserver.client (:use [bulbs.base.client :only [ClientProtocol]])) (deftype Neo4jClient [ns config] ClientProtocol (create-edge [this outV label inV data] (let [inV-uri (utils/normalize-uri (build-path neo4j-uri vertex-path inV)) path (build-path vertex-path, outV, "relationships") params {:to inV-uri, :type label, :data (first data)}] (post config path params))) (create-edge [this outV label inV] ;; it doesn't like this call... (create-edge this outV label inV nil))
当第二种方法尝试调用第一种方法时,它会发出此错误:
java.lang.RuntimeException: Unable to resolve symbol: create-edge in this context
当我使用第一个函数编译它时,我在SLIME中使用了两个定义,然后返回并添加了第二个。
但是当我将协议定义移动到一个单独的文件并尝试重新编译整个文件时,它会在第二个方法尝试调用第一个方法时抛出错误,大概是因为第一个方法尚未定义。
Clojure
reify
docs有这样的评论:如果方法在协议/接口中过载,则必须提供多个独立的方法定义。
http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/reify
我想这些不是独立的定义。
什么是正确的方法来解决这个问题?
Here's part of an overloaded protocol definition:
(defprotocol ClientProtocol (create-edge [this outV label inV] [this outV label inV data])
And here's part of its implementation:
(ns bulbs.neo4jserver.client (:use [bulbs.base.client :only [ClientProtocol]])) (deftype Neo4jClient [ns config] ClientProtocol (create-edge [this outV label inV data] (let [inV-uri (utils/normalize-uri (build-path neo4j-uri vertex-path inV)) path (build-path vertex-path, outV, "relationships") params {:to inV-uri, :type label, :data (first data)}] (post config path params))) (create-edge [this outV label inV] ;; it doesn't like this call... (create-edge this outV label inV nil))
It's spewing this error when the second method tries to call the first:
java.lang.RuntimeException: Unable to resolve symbol: create-edge in this context
I had both definitions working earlier in SLIME when I compiled it with the first function and then went back and added the second.
But when I moved the protocol definition into a separate file and tried to re-compile the whole thing, it throws an error when the second method tries to call the first, presumably because the first method hasn't been defined yet.
The Clojure
reify
docs have this comment:If a method is overloaded in a protocol/interface, multiple independent method definitions must be supplied.
http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/reify
I suppose these are not independent definitions.
What's the right way to approach this?
原文:https://stackoverflow.com/questions/10645155
最满意答案
按照以下几个步骤
1)将数据收集到变量或数组中
2)与数据库建立连接
3)使您的数据库处于可写模式
4)fire insert查询并关闭数据库
Follow this few steps
1) collect data into variable or in Array
2) make connection with database
3) get your database in writeable mode
4) fire insert query and close your database
相关问答
更多-
如何将数据从一个应用程序发送到android中的其他应用程序?(How to send data from one application to other application in android?)[2022-06-10]
据我的理解你的答案你正在寻找意图: 在App A - Activity Alpha的清单中,您声明了一个类别为DEFAULT的意向过滤器,并且Action = com.your_app_package_name.your_app_name.ActivtiyAlpha 在应用程序B,活动测试版中,您将代码启动并传递数据: Intent i = new Intent("com.your_app_package_name.your_app_name.ActivtiyAlpha"); i.putExtra("KEY ... -
您可以使用简单的p2p架构。 您将需要使用this , this和一对与您需要发送的数据类型相关的流,如下所示 。 在发件人方面: Socket s = new Socket(IP,PORT); s.connect(); DataOutputStream dos = new DataOutputStream(s.getOutputStream()); dos.write("hello".toByteArray()); 然后在接收方: ServerSocket ss = new ServerSocket(P ...
-
您应该为此创建一个后台线程。 您可以使用AsyncTask ,或通用Java Thread类,或使用Runnable的ExecutorService。 AsyncTask的问题是,在第一个子类被销毁之前,你不能使用超过1个AsyncTask子类。 并且在完成后自动销毁它有点复杂。 有关AsyncTask的说明: http : //developer.android.com/reference/android/os/AsyncTask.html 关于Java线程的说明: http : //docs.oracl ...
-
这是错的: request.ContentType = "Content-Type: application/json" 将其更改为: request.ContentType = "application/json" 一个简短的解释: 由于您发送的内容类型无效,因此Google使用默认内容类型,即application/x-www-form-urlencoded;charset=UTF-8 。 并且期望这种内容类型,他们没有找到注册ID,导致MissingRegistration 。 This is wro ...
-
安全地在android中将二进制数据从一个应用程序发送到另一个(Send binary data from one application to another in android, securely)[2022-02-26]
您希望使用内容提供商从单个应用程序共享数据并从第二个应用程序检索代码。 查看此示例并从其他应用程序共享相同的内容URL以检索加密数据。 You want to use content provider to share data from single app and to retrieve code from your second app. Look at this example and share same content URL from other app to retrieve encrypt ... -
按照以下几个步骤 1)将数据收集到变量或数组中 2)与数据库建立连接 3)使您的数据库处于可写模式 4)fire insert查询并关闭数据库 Follow this few steps 1) collect data into variable or in Array 2) make connection with database 3) get your database in writeable mode 4) fire insert query and close your database
-
通过蓝牙将数据从Android应用程序发送到串行COM端口(Send data from an android app to a Serial COM Port via Bluetooth)[2022-12-17]
我想你必须在手机和电脑之间进行配对,以建立一个频道(一个RfComm频道)来交换数据。 我建议你从商店下载这样的蓝牙终端: https : //play.google.com/store/apps/details?id = es.pymasde.blueterm&hl = en I had actually 2 problems going on : I had to go in the settings of my Bluetooth dongle and create a Bluetooth COM P ... -
你想要做的可能是执行HTTP POST。 这在Java中非常简单,只需使用HttpURLConnection类。 例如,你可以做这样的事情。 URL url = new URL("www.yoursite.com"); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); //Send request DataOutputStream wr = new DataOutputStream (urlConn ...
-
使用Android应用程序的输入数据自动填充网站的一种形式(Autofill a form of a website with input data of an android app)[2023-05-17]
将代码更新为以下内容: // Get user defined values Name = "your username here"; Email = "email"; Login = "user"; Pass = "password"; // Create data variable for sent values to server Strin ... -
更好但更复杂的方法是使用Google Cloud Messaging (又称推送通知)。 通过这种方式,您的服务器可以通知应用程序有新数据需要检索,然后您的应用程序才能查询您的服务器。 这是一种更加电池友好的方法,效果很好。 出于同样的原因,我之前使用过它。 为了回答一些评论,民意调查是一个坏主意,因为 它没有任何理由过度使用您的服务器和用户的设备 它会耗尽用户的电池 服务器想要与应用程序通信的时间与应用程序进行下一次轮询的时间之间总会有一些延迟。 推送通知方法需要付出更多努力,但也具有很大的优势。 A b ...