clojure-java-interop

Convert from clojure.lang.LazySeq to type org.apache.spark.api.java.JavaRDD

一个人想着一个人 提交于 2019-12-11 11:14:49
问题 I developed a function in clojure to fill in an empty column from the last non-empty value, I'm assuming this works, given (:require [flambo.api :as f]) (defn replicate-val [ rdd input ] (let [{:keys [ col ]} input result (reductions (fn [a b] (if (empty? (nth b col)) (assoc b col (nth a col)) b)) rdd )] (println "Result type is: "(type result)))) Got this: ;=> "Result type is: clojure.lang.LazySeq" The question is how do I convert this back to type JavaRDD, using flambo (spark wrapper) I

Convert from clojure.lang.LazySeq to type org.apache.spark.api.java.JavaRDD

妖精的绣舞 提交于 2019-12-11 03:57:38
问题 I developed a function in clojure to fill in an empty column from the last non-empty value, I'm assuming this works, given (:require [flambo.api :as f]) (defn replicate-val [ rdd input ] (let [{:keys [ col ]} input result (reductions (fn [a b] (if (empty? (nth b col)) (assoc b col (nth a col)) b)) rdd )] (println "Result type is: "(type result)))) Got this: ;=> "Result type is: clojure.lang.LazySeq" The question is how do I convert this back to type JavaRDD, using flambo (spark wrapper) I

Strange aget optimisation behavior

久未见 提交于 2019-12-10 17:34:57
问题 Followup on this question about aget performance There seems to be something very strange going on optimisation wise. We knew the following was true: => (def xa (int-array (range 100000))) #'user/xa => (set! *warn-on-reflection* true) true => (time (reduce + (for [x xa] (aget ^ints xa x)))) "Elapsed time: 42.80174 msecs" 4999950000 => (time (reduce + (for [x xa] (aget xa x)))) "Elapsed time: 2067.673859 msecs" 4999950000 Reflection warning, NO_SOURCE_PATH:1 - call to aget can't be resolved.

calling clojure from Java (Clojure Interop)

懵懂的女人 提交于 2019-12-10 10:57:15
问题 Calling Java from Clojoure is quite simple and straightforward but the inverse has proven to be unpredictable. They seem to be two ways of doing it: 1)the following classes i) import clojure.java.api.Clojure; , ii) import clojure.lang.IFn; 2)compile your clojure into an uberjar then import it into the java code. I have opted for the 2nd option as it's more straight forward. Here is the clojure code (ns com.test.app.service (:gen-class :name com.test.app.service :main false :methods [^{:static

How to require java classes in clojure/leiningen

二次信任 提交于 2019-12-10 09:47:09
问题 I am testing out Clojure/Java interop. I created a new Leiningen project and created this project.clj file with a few dependencies I'll be using: (defproject kente "0.1.0-SNAPSHOT" :description "FIXME: write description" :url "http://example.com/FIXME" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[org.clojure/clojure "1.4.0"] [ring/ring-jetty-adapter "1.0.0-RC1"] [compojure "0.6.5"] [hiccup "0.3.7"] [cheshire "5.0.1"]] :java-source

How do you configure proprietary dependencies for Leiningen?

眉间皱痕 提交于 2019-12-09 12:55:44
问题 We're working on a project that has some Clojure-Java interop. At this point we have a single class that has a variety of dependencies which we put into a user library in Eclipse for development, but of course that doesn't help when using Leiningen (2.x). Most of our dependencies are proprietary, so they aren't on a repository somewhere. What is the easiest/right way to do this? I've seen leiningen - how to add dependencies for local jars?, but it appears to be out of date? Update: So I made

Clojure reify a Java interface with overloaded methods

核能气质少年 提交于 2019-12-07 04:37:35
问题 I'm trying to implement the following Java interface in Clojure: package quickfix; public interface MessageFactory { Message create(String beginString, String msgType); Group create(String beginString, String msgType, int correspondingFieldID); } The following Clojure code is my attempt at doing this: (defn -create-message-factory [] (reify quickfix.MessageFactory (create [beginString msgType] nil) (create [beginString msgType correspondingFieldID] nil))) This fails to compile with the error:

Is it possible to use Clojure's case form with a Java enum?

若如初见. 提交于 2019-12-06 20:05:59
问题 The case doc says Unlike cond and condp, case does a constant-time dispatch... All manner of constant expressions are acceptable in case. I would like to benefit from case 's constant-time dispatch to match on Java enums. Java's switch statement works well with enums, but doing the following in Clojure: (defn foo [x] (case x java.util.concurrent.TimeUnit/MILLISECONDS "yes!")) (foo java.util.concurrent.TimeUnit/MILLISECONDS) Results in: IllegalArgumentException No matching clause: MILLISECONDS

calling clojure from Java (Clojure Interop)

拈花ヽ惹草 提交于 2019-12-06 10:13:05
Calling Java from Clojoure is quite simple and straightforward but the inverse has proven to be unpredictable. They seem to be two ways of doing it: 1)the following classes i) import clojure.java.api.Clojure; , ii) import clojure.lang.IFn; 2)compile your clojure into an uberjar then import it into the java code. I have opted for the 2nd option as it's more straight forward. Here is the clojure code (ns com.test.app.service (:gen-class :name com.test.app.service :main false :methods [^{:static true} [returned [int] int]])) (defn returned [number] (* 2 number)) (defn -returned [number] (returned

Clojure Leining REPL OutOfMemoryError Java heap space

青春壹個敷衍的年華 提交于 2019-12-06 03:04:28
问题 I am trying to parse a fairly small (< 100MB) xml file with: (require '[clojure.data.xml :as xml] '[clojure.java.io :as io]) (xml/parse (io/reader "data/small-sample.xml")) and I am getting an error: OutOfMemoryError Java heap space clojure.lang.Numbers.byte_array (Numbers.java:1216) clojure.tools.nrepl.bencode/read-bytes (bencode.clj:101) clojure.tools.nrepl.bencode/read-netstring* (bencode.clj:153) clojure.tools.nrepl.bencode/read-token (bencode.clj:244) clojure.tools.nrepl.bencode/read