clojure

A regex to match a substring that isn't followed by a certain other substring

半城伤御伤魂 提交于 2019-12-17 03:51:25
问题 I need a regex that will match blahfooblah but not blahfoobarblah I want it to match only foo and everything around foo, as long as it isn't followed by bar. I tried using this: foo.*(?<!bar) which is fairly close, but it matches blahfoobarblah . The negative look behind needs to match anything and not just bar. The specific language I'm using is Clojure which uses Java regexes under the hood. EDIT: More specifically, I also need it to pass blahfooblahfoobarblah but not blahfoobarblahblah .

How to handle java variable length arguments in clojure?

佐手、 提交于 2019-12-17 03:19:11
问题 I'am wrapping a java lib into clojure, but i have problems dealing with variable length arguments. Say, TestClass.aStaticFunction(Integer... intList){/*....*/} How could i call this function in clojure? 回答1: Since Java varargs are actually arrays, you can call vararg functions in Clojure by passing an array. You could convert a Clojure seq (maybe by using Clojure's variety of variable argument functions) into an array: (TestClass/aStaticFunction (into-array Integer [(int 1),(int 2)])) or

Generating permutations lazily

試著忘記壹切 提交于 2019-12-17 02:54:53
问题 I'm looking for an algorithm to generate permutations of a set in such a way that I could make a lazy list of them in Clojure. i.e. I'd like to iterate over a list of permutations where each permutation is not calculated until I request it, and all of the permutations don't have to be stored in memory at once. Alternatively I'm looking for an algorithm where given a certain set, it will return the "next" permutation of that set, in such a way that repeatedly calling the function on its own

Is there a Haskell idiom for updating a nested data structure?

风流意气都作罢 提交于 2019-12-17 02:38:10
问题 Let's say I have the following data model, for keeping track of the stats of baseball players, teams, and coaches: data BBTeam = BBTeam { teamname :: String, manager :: Coach, players :: [BBPlayer] } deriving (Show) data Coach = Coach { coachname :: String, favcussword :: String, diet :: Diet } deriving (Show) data Diet = Diet { dietname :: String, steaks :: Integer, eggs :: Integer } deriving (Show) data BBPlayer = BBPlayer { playername :: String, hits :: Integer, era :: Double } deriving

How to bundle a native library and a JNI library inside a JAR?

99封情书 提交于 2019-12-17 01:39:14
问题 The library in question is Tokyo Cabinet. I want is to have the native library, JNI library, and all Java API classes in one JAR file to avoid redistribution headaches. There seems to be an attempt at this at GitHub, but It does not include the actual native library, only JNI library. It seems to be specific to Leiningen's native dependencies plugin (it won't work as a redistributable). The question is, can I bundle everything in one JAR and redistribute it? If yes, how? P.S.: Yes, I realize

Macros and functions in Clojure

雨燕双飞 提交于 2019-12-14 04:17:38
问题 I read the following line in this Clojure tutorial - http://java.ociweb.com/mark/clojure/article.html#Macros 'Since macros don't evaluate their arguments, unquoted function names can be passed to them and calls to the functions with arguments can be constructed. Function definitions cannot do this and instead must be passed anonymous functions that wrap calls to functions.' If it is correct, then why does this work since the function cube is not anonymous- (defn something [fn x] (fn x)) (defn

How to pass list as a parameter to a clojure function

笑着哭i 提交于 2019-12-14 03:55:15
问题 How to pass list(collection) as a parameter to a clojure function, this clojure is called by java code. 回答1: Clojure: (ns utils ; Sets the namespace to utils (:gen-class :name Utils ; The keyword :gen-class declares that ; I want this compiled as a class. The ; :name declares the name (and the package) ; of the class I want created. :methods [#^{:static true} [sum [java.util.Collection] long]])) ; In the vector following :methods I've declared ; the methods I want to have available in the ;

Using maven's “LATEST” keyword in leiningen project

江枫思渺然 提交于 2019-12-14 03:54:24
问题 I have two leiningen projects. According to this question, maven should allow me to use "LATEST" as a dependency version. It is giving me an error suggesting that the dependency with version "LATEST" can't be found. This answer represents how I'm referencing this project locally with leiningen, if that matters. How do I get this to work? If this isn't how you reference local dependencies in your project, I'm open to alternative suggestions. The project files look like this: (defproject mongo

How to unload a function from another namespace?

半世苍凉 提交于 2019-12-14 03:52:49
问题 I load a function say-hi from namespace learning.greeting (use 'learning.greeting) When I try to re-defn the say-hi function under the current (user) namespace, I got the error: CompilerException java.lang.IllegalStateException: say-hi already refers to: #'learning.greeting/say-hi in namespace: user, compiling:(NO_SOURCE_PATH:1:1) So how to unload the function from other namespaces? 回答1: If you want to get rid of a direct mapping to a Var from another namespace at the REPL, say (ns-unmap

Partial vs function literal when memoize

淺唱寂寞╮ 提交于 2019-12-14 03:45:58
问题 This is giving me a bit of brain thump: user> (repeatedly 10 #((memoize rand-int) 10)) (7 0 4 8 1 2 2 1 6 9) user> (repeatedly 10 (partial (memoize rand-int) 10)) (8 8 8 8 8 8 8 8 8 8) I would like to know if the reason for this is because the function literal (first version) is called/evaluated every time, thus the memoize is "recreated" (re-memorized) each time, therefore not really having any true meaningful "memorization" at all, while the second one with partial is actually returning a