clojure

Maybe in clojure

混江龙づ霸主 提交于 2020-01-06 02:45:07
问题 Trying to write a composed function in clojure that exits at the first nil value, (e.g something you'd do by chaining Maybes together in haskell) with the following: (defn wrap [f] (fn [x] (if (nil? x) nil (f x)))) (defn maybe [arg & functs] ( (comp (reverse (map wrap functs))) arg)) So that I'd get, e.g. (defn f1 [x] (+ x 1)) (maybe 1 f1 f1 ) => 3 (maybe nil f1 f1) => nil Which is unfortunately giving me this: ClassCastException clojure.lang.PersistentList cannot be cast to clojure.lang.IFn

Stanford CoreNLP pipeline coref: parsing some short strings (with few mentions) returns indexoutofbounds exception

倾然丶 夕夏残阳落幕 提交于 2020-01-06 01:54:39
问题 BACKGROUND: I'm importing the Stanford CoreNLP library into my clojure project. I was using version 3.5.1 but recently jumped directly into version 3.6.0, bypassing 3.5.2. As part of this update, because I was getting coreference information using the dcoref annotator, I needed to make small modifications so that my program used the coref annotator instead. In the past (v3.5.1), when I created a pipeline with the following annotators "tokenize, ssplit, pos, lemma, ner, parse, depparse, dcoref

atom is slow when using it with big map

雨燕双飞 提交于 2020-01-05 10:06:12
问题 I have an ETL using clojure, each thread could load different part of a file, and it also needs to get a key from business key. The data structure to store the business key to key mapping is a hash map like: {"businessKey1" 1, "businessKey2" 2, "businessKey3" 3, "businessKey4" 4, "businessKey5" 5 } When ETL loading data from file, it parses each line from the file into columns, if the business key column could be found in the map, just return the key, e.g if it found businessKey1, then return

atom is slow when using it with big map

こ雲淡風輕ζ 提交于 2020-01-05 10:05:52
问题 I have an ETL using clojure, each thread could load different part of a file, and it also needs to get a key from business key. The data structure to store the business key to key mapping is a hash map like: {"businessKey1" 1, "businessKey2" 2, "businessKey3" 3, "businessKey4" 4, "businessKey5" 5 } When ETL loading data from file, it parses each line from the file into columns, if the business key column could be found in the map, just return the key, e.g if it found businessKey1, then return

Clojure Macro using filter returns an object reference. Do not know how to interpret this reference

血红的双手。 提交于 2020-01-05 08:39:09
问题 I am defining this macro seminar.core=> (defmacro select #_=> [vara _ coll _ wherearg _ orderarg] #_=> `(filter ~wherearg)) #'seminar.core/select And then defining a table (def persons '({:id 1 :name "olle"} {:id 2 :name "anna"} {:id 3 :name "isak"} {:id 4 :name "beatrice"})) When I try to run my macro , so that I get the columns from the table where the id is greater than 2 (i.e {:id 3 :name "isak"} {:id 4 :name "beatrice"} ) seminar.core=> (select [:id :name] from persons where [> :id 2]

lein run exits without running all of my -main function

╄→гoц情女王★ 提交于 2020-01-05 04:10:09
问题 Here's my project.clj : (defproject fixurls "0.1.0-SNAPSHOT" :description "Fixurls" :url "https://github.com/swizzard/fixurls" :license {:name "WTFPL" :url "http://www.wtfpl.net/"} :dependencies [[org.clojure/clojure "1.5.1"] [clj-http "0.9.2"] [org.clojure/data.json "0.2.4"] [me.raynes/fs "1.4.4"] ] :plugins [[lein-gorilla "0.2.0"]] :jvm-opts ["-Xmx4g" "-Xms2g" "-Xss1g" "-server"] :main ^:skip-aot fixurls.core ) Here's ~/clojure-stuff/fixurls/src/core.clj : (ns fixurls.core (:require [clj

How to debug a Clojure file in IntelliJ?

落爺英雄遲暮 提交于 2020-01-04 21:39:12
问题 No breakpoint can be set on line 5, which contains [x] . IntelliJ won't let me do so. I used different plugin, such as La Clojure and Cursive. Both stop at line 3 rather than line 5. So, how people step into the code in Clojure? Is there any syntax suggestion or maybe tool to help with? (defn flattenlist ([x & more] (concat (if (vector? x) (apply flattenlist x) [x] ) (if (= more nil) nil (apply flattenlist more)))) ) (flattenlist [[1 [[2]]] 3 [4 5] 6]) 回答1: First, by convention, all trailing

What is the difference and issues between these two clojure functions?

ぃ、小莉子 提交于 2020-01-04 15:26:37
问题 For part of a class project I am implementing a function to read some data from a file and create a graph structure based on the file. Throughout the day I have asked a few questions and it has come down to this. Below is a function that works as it should. It first reads in a file as a lazy sequence and then loops over the sequence parsing each line and printing it out. (defn printGraph [filename, numnodes] (with-open [rdr (io/reader filename)] (let [lines (line-seq rdr)] (loop [curline

Determine namespace of a function's caller

会有一股神秘感。 提交于 2020-01-04 14:29:26
问题 I'm trying to accurately determine the namespace of a function's caller. Looks like *ns* is determined by the namespace at top of the call stack. user=> (ns util) nil util=> (defn where-am-i? [] (str *ns*)) #'util/where-am-i? util=> (ns foo (:require [util])) nil foo=> (util/where-am-i?) "foo" foo=> (ns bar) nil bar=> (defn ask [] (util/where-am-i?)) #'bar/ask bar=> (ask) "bar" bar=> (ns foo) nil foo=> (util/where-am-i?) "foo" foo=> (bar/ask) "foo" foo=> Is there some other meta data I can

How do you explicitly specify a namespace when using “apply” on a function in Clojure?

[亡魂溺海] 提交于 2020-01-04 14:03:11
问题 Here "graph" is higher-order function that returns a function with config set in its scope: (ns bulbs.neo4jserver.graph) (defn out1 "Test func that simply returns out1." [config] "out1") (defn graph [config] (fn [func & args] (apply func config args))) You create an instance of graph, which can then be used to call other functions and automatically pass in the config arg: (def g (graph {:root-uri "http://localhost"})) (g out1) ;; => "out1" This works; however, if you require/import graph into