clojure

Push to Nexus Using Leiningen

I wrote a Clojure project using Leiningen and would now like to add the resulting jar to a Sonatype Nexus server. I installed lein-clojars, since this comes with a push command that seems to accept an optional repo arg if you would like to push somewhere besides Clojars. However, whenever I try this, I get a JSchException: Auth fail. It ...

How do I connect a clojure source file to a running clojure repl on Emacs?

I'm currently in the process of adding functionality to an existing J2EE webapp, in a Tomcat container, and I'm writing my additions using Clojure. My setup is simple: I just add calls to static methods generated by clojure, and code all the hard work from the clojure side. The build process consists in compiling clojure code (lein uberj...

Syntax-aware substring replacement

I have a string containing a valid Clojure form. I want to replace a part of it, just like with assoc-in, but processing the whole string as tokens. => (assoc-in [:a [:b :c]] [1 0] :new) [:a [:new :c]] => (assoc-in [:a [:b,, :c]] [1 0] :new) [:a [:new :c]] => (string-assoc-in "[:a [:b,, :c]]" [1...

Clojure namespace management - Is there a way to save and restore the state of clojure repl namespaces, imports etc. ?

Clojure has a large number functions/macros for working with namespaces and java package imports. To my (limited) understanding the set up of namespaces can be considered state in a clojure process (repl). When working iteratively at a REPL session, especially when source files are (re)-loaded, I can find it easy to get confused - often...

Calling fnparse to parse a string?

I've been trying out fnparse library written by Joshua Choi in Clojure and I'm having difficulties trying to work out how to call the rules on the text that I want to parse. I've been experimenting with cat which is part of the new release. Lets take the example code listed. Could anyone give me some ideas how I could call the rule on a...

How many primitives does it take to build a LISP machine? Ten, seven or five?

On this site they say there are 10 LISP primitives. The primitives are: atom, quote, eq, car, cdr, cons, cond, lambda, label, apply. http://hyperpolyglot.wikidot.com/lisp#ten-primitives Stevey reckons there are seven (or five): Its part of the purity of the idea of LISP: you only need the seven (or is it five?) primitives to build ...

Applying the Y-Combinator to a recursive function with two arguments in Clojure?

Doing the Y-Combinator for a single argument function such as factorial or fibonacci in Clojure is well documented: http://rosettacode.org/wiki/Y_combinator#Clojure My question is - how do you do it for a two argument function such as this getter for example? (Assumption here is that I want to solve this problem recursively and this n...

What is it about a single namespace that leads to unhygienic macros? (in LISP)

Some claim that a single namespace in LISP leads to unhygienic macros. http://community.schemewiki.org/?hygiene-versus-gensym http://www.nhplace.com/kent/Papers/Technical-Issues.html What precisely is it about having single, dual or multiple namespaces that leads to macro hygiene? ...

What's the "big idea" behind compojure routes?

I'm new to Clojure and have been using Compojure to write a basic web application. I'm hitting a wall with Compojure's defroutes syntax, though, and I think I need to understand both the "how" and the "why" behind it all. It seems like a Ring-style application begins with an HTTP request map, then just passes the request through a seri...

Purely functional concurrent skip list

Skip lists (Pugh, 1990) provide sorted dictionaries with logarithmic-time operations like search trees but skip lists are much more amenable to concurrent updates. Is it possible to create an efficient purely functional concurrent skip list? If not, is it possible to create any kind of efficient purely functional concurrent sorted dicti...

Use for the identity monad in Clojure

I've been reading an excellent introduction to monads for Clojure programmers. The article illustrates that the Identity monad is functionally equivalent to Clojure's let and that the Sequence/List monad is equivalent to for. When the article gets to monad transformers, it shows an example combining the Maybe and Sequence monads. Ok, s...

What is the correct term for the following functional programming pattern?

I've heard it referred to as a stream, as an infinite list, and sometimes even as a lazy sequence. What is the correct term for the following pattern? (Clojure code shown) (def first$ first) (defn second$ [str] (cond (empty? str) () true ((first (rest str))))) (defn stream-builder [next_ n] (cons n (cons (fn [] (stream-bu...

How to apply clojure?

I am learning Clojure and I really am loving some of its features. The time is coming to think of some real "pet projects" and I realize I'm not sure how to actually use Clojure. I see many web and templating frameworks (e.g. Compojure), but somehow I'm in doubt on whether it's worth it. I feel that in the long run it can't serve the ne...

Looking for a JVM language without the cruft, should I pick Scala, Groovy, or something else?

I've been programming in Java for the last few years, but due to disappointment with the current state of the language I'd like to switch to another JVM language with all the goodies of dynamic languages and features like closures, etc. I've looked around and Scala and Groovy seem the most popular choices. Am I missing other good languag...

Estimating the word count of a file without reading the full file

I have a program to process very large files. Now I need to show a progress bar to show the progress of the processing. The program works on a word level, read one line at a time, splitting it into words and processing the words one by one. So while the programs runs, it knows the count of the words processed. If somehow it knows the wor...

Will the clojure compiler automatically evaluate expressions of literals at compile time?

This might be a silly question, but: Suppose an expression depends only on literals, or on other expressions that also only depend on literals; will the compiler evaluate this at compile time? Suppose I have, (def a (some-time-consuming-function some-literal)) (def b (some-other-time-consuming-function a)) Will both b and a be eva...

Clojure for trading strategies

Is anybody using closure for developing automated trading strategies? What is your experiences? I am anticipating learning clojure and wanted to know if i could use it in this context, if there are any resources to using it in this context pls provide a link. I am currently only using ruby and javascript for web development. Kind Regard...

Why is the weird ' usage for ns/use with Clojure?

I define namespace inside a clojure lib without ', (ns myproject.hello) But, I use ' for using it. (use 'myproject.hello) Why is this? Is there any logic behind this? In gosh (dialect of scheme), I use without ' i.e. (use myproject) Why is this irregularity? ...

Java for clojure users.

I've been using Lisp on and off, and I'm catching up with clojure. The good thing about clojure is that I can use all the java functions naturally, and the bad thing about clojure is also that I have to know java function naturally. For example, I had to spend some time (googling) to find square function in Java (Math/sqrt in clojure n...

What does the future look like for Java Applets?

In the past, java applets were unreliable, due to the Microsoft/Sun JVM split. Flash took over, and Java applets became known for browser crashes and performance issues. Now that the JVM is enjoying resurgence as a platform for dynamic languages like Clojure and Scala, what is the current and future outlook for the JVM for in-browser ap...