Clojure is a Lisp dialect for the Java Virtual Machine. Its main features include a software transactional memory system for coherent updates to data structures, transparent access to Java libraries, a dynamic REPL development environment, runtime polymorphism, and built-in concurrent programming ...

learn more… | top users | synonyms

1
vote
0answers
73 views

API wrapper for Clojure, idiomatic style for libraries?

I wanted to wrap the jkeymaster library in a Clojure wrapper (for my own use, but perhaps also to save others some time). I'm just learning Clojure so I'm still not quite sure what "idiomatic ...
3
votes
0answers
163 views

Connect Four AI (Minimax) in Clojure

I wrote a Connect Four game inlcuding a AI in Clojure and since I'm rather new to Clojure, some review would be highly appreciated. It can include everything, coding style, simplifications, etc. But ...
0
votes
1answer
37 views

Clojure: Idiomatic use of atom and ref?

I am working out a bit of Clojure code that will take a ref to a map and increment a key value pair in the map. I think I am using ref correctly, but Im not sure about atom. Do I need to use swap! ...
2
votes
2answers
60 views

clojure - finding first match in recursive search

I am searching a recursive solution space and would like to return the first match I find. (I am using this to solve sudoku, but I guess this would apply to any recursively defined problem or ...
2
votes
0answers
66 views

single-threaded socket server

I wrote a basic Clojure single-threaded socket server, mostly following Java examples; in particular I'd appreciate feedback on three things, how I handle mutable state (I/O, managing connections). ...
3
votes
2answers
77 views

Mergesort implementation in Clojure

(defn merge [pred left right] (loop [v [] l left r right] ; v is a vector, so conj will append to the end (if (and (seq l) (seq r)) ; if both left and right are not empty (if ...
4
votes
2answers
88 views

Is there a better way to extract a single value instead of a sequence?

The following code works, but I'd like to re-write, so that a single index is returned, rather than a sequence of indexes visited. Here are the defs and function. (def usage-vec-len 13) (def ...
5
votes
1answer
112 views

Excessive use of let a problem in Clojure?

I have this set of functions - it works, but I'm concerned about the use of lets. (defn- create-counts [coll] "Computes how many times did each 'next state' come from a 'previous state'. The ...
2
votes
0answers
72 views

Making my back-propagation clojure code more idiomatic

I've written an implementation of the back-propagation algorithm in clojure (here). This is my first attempt at clojure where the code totals more than ten lines and so it is not very idiomatic; ...
1
vote
2answers
95 views

Discovering words from letters in Clojure (Letterpress Solver)

I created a Letterpress solver that will take a string of letters and return a list of valid words that can be constructer with the provided letters. Not all letters need to be used in each word. ...
2
votes
1answer
126 views

Idiomatic Clojure? Performant & functional enough?

Problem Disclaimer: This is my first clojure function & I'm still busy finishing the last chapters of "Programming Clojure". Thanks! :) I am writing a function to randomly flood-fill parts of a ...
1
vote
1answer
64 views

How can I simplify the following to avoid sequence of maps?

Given the following code, I have written a for loop that returns a key and value (0 or 1) of file names passed. 1 means present, and 0 means not present. Is there a way to construct a flat map ...
2
votes
0answers
121 views

Inverted index in Clojure - performance vs. idiomatic code

I have this code to create an inverted index from a directory of text files: (def p (re-pattern #"[^\p{L}&&[^\p{M}]]")) (defn invert[file] (let [f (.getName file) tokens (.split p ...
4
votes
0answers
119 views

Shepard Tone stream generation in Clojure

This is my work to generate an infinite Shepard Tone. It is written in Clojure and works by generating repeating streams of incrementing frequencies, converting those to values on a sine wave and then ...
0
votes
0answers
79 views

Shuffling algorithms by a Clojure Novice

The shuffle descriptions can be seen here... Shuffling Am I using Clojure idioms and going with the grain of the language? A few things that concern me.. Am I doing too much logic in my let ...
2
votes
1answer
71 views

Calculating pi in clojure - any suggestions

Clojure newbie here, trying to get my head around it. Obviously there are better ways of obtaining pi, but for educational purposes, how is the code below? (defn leibniz-numerator [x] (* (- (rem x 4) ...
5
votes
1answer
111 views

First Go at Clojure and Functional Programming in General

Here's the code... My goal is to simulate a Pile shuffle of a vector. Here's the function.. (defn pile ([cards] (pile cards 3 1)) ([cards num_piles] (pile cards num_piles 1)) ([cards ...
1
vote
1answer
57 views

Clojure: Find specific element in HTML tree

I am trying to find all "link" elements that link to RSS feeds in a data structure created by clj-tagsoup. I wrote the following code, which seems to work fine. But: I come from a Java background and ...
0
votes
1answer
61 views

Idiomatic letterpress cheater

Hello dear Code Reviewers, I'm playing around with Clojure and am having a lot of fun. It's quite hard to go from imperative languages to Clojure, and I need some guidance on how to make the ...
4
votes
1answer
88 views

String-splitting function

This function was hard to write as a Clojure newbie, and I don't like the result. Can you help me find a better (more readable) way to do it? (defn split-seq "Splits a seq into blocks defined by ...
5
votes
4answers
263 views

How to write this small program better?

This is just a fun little exercise I had to do for a homework once (in Java rather than Clojure though). Basically, the goal is to find the number of different coin stacks you can build with the coins ...
4
votes
3answers
223 views

Critique my Clojure “Game of Life” code

I'm a Clojure n00b (but am experienced with other languages) and am learning the language as I find time - enjoying it so far, though the strange dreams and accidental use of parenthesis elsewhere ...
1
vote
1answer
75 views

Idiomatic text munging in Clojure

In getting accustomed to Clojure syntax, I wrote the following stutter function: (defn doublelist [coll] (flatten (map (fn [x] [x x]) coll))) (defn stutter [s] (clojure.string/join " " ...
2
votes
1answer
128 views

Find largest two numbers from list using clojure

I'm trying to write a function that finds the largest two numbers from a list of positive integers in Clojure. I've toyed around with Scheme in the past, but I'm very new to Clojure. This is what I ...
2
votes
2answers
92 views

More concise and/or idiomatic max subarray in Clojure?

I've implemented the following two versions of the classic "Max Sub-Array" problem in Clojure, using the Kadane algorithm. First with loop / recur (defn max-sub-array [A] (loop [x (first A) ...
5
votes
1answer
255 views

Depth-first search algorithm in clojure

Context As an exercise for myself (I'm learning clojure). I wanted to implement the Depth-first search algorithm. How I did it Using recursion (def graph {:s {:a 3 :d 4} :a {:s 3 :d 5 :b 4} ...
3
votes
1answer
221 views

Connect Four: Bitboard checking algorithm

I'm rather new to Clojure and so I decided to program a Connect Four for fun and learning. The code below is a Clojure implementation of this bitboard algorithm. The whole code can be found here: ...
0
votes
1answer
104 views

Calculating a factorial with parallel sub-computations using pmap, pvalues and pcalls

In an attempt to learn more about Clojure's parallel computation functions, I devised the following task: calculate a factorial in parallel using pmap, pcalls and pvalues. The idea is to split the ...
3
votes
0answers
77 views

Toggle chart series in clojurescript

I'm toggling on/off series in chart and was wondering if I was doing anything crazy. Is the atom really a good idea here? ;; ================ Graph data ================ (def serie1 {:label "Bar" ...
3
votes
1answer
140 views

Implementation of Python's re.split in Clojure (with capturing parentheses)

If you use capturing parenthesis in the regular expression pattern in Python's re.split() function, it will include the matching groups in the result (Python's documentation). I need this in my ...
6
votes
2answers
194 views

Expanding a map, style guidance

I have a map that I want to 'expand' into an infinite sequence in the following manner: {0 'zero 3 'three 10 'ten} => ('zero 'zero 'zero 'three 'three 'three 'three 'three 'three 'three 'ten 'ten ...
4
votes
2answers
551 views

higher order fizzbuzz! clojure

make it better! requirement: support arbitrary number of factors, not just 3 & 5. (ns fizzbuzz.core (:use [clojure.contrib.string :only (join)])) (def targets (sorted-map 3 "fizz" 5 "buzz" 7 ...
4
votes
3answers
676 views

Find the common characters between two strings without using set operations

Below are two implementations of the problem "find the characters in common between two strings" - in Clojure without using collections / set operations. Are these approaches sufficiently idiomatic ...
7
votes
2answers
271 views

Powerset in Clojure

I think I have correctly implemented Powerset in Clojure. (use '(clojure set)) (defn powerset [input result] (if (nil? (first input)) (concat result #{}) (set (reduce concat ...
6
votes
1answer
363 views

Clojure TicTacToe (Logic, no Gui)

I whipped this up last night and was wondering if anyone had any thoughts/comments on it; for example, on: Code organisation Coding style Other improvements Semantic errors All feedback is ...
7
votes
1answer
150 views

Tips on good clojure style

I've implementing this algorithm in Java, Scala, and Clojure to show my team-mates. I know the code works as expected. What I'm looking for is tips on good clojure style. (ns gaming.online.ranking ...
2
votes
1answer
200 views

idiomatic clojure (map from sequence generation)

It's my first clojure script (simple word translator based on wikipedia), and I guess there are things which could be simplified / done more idiomatic way. Specifically, I wonder if get-translations ...
3
votes
2answers
309 views

Clojure MapReduce Reducer

This program forms the reducer of a Hadoop MapReduce job. It reads data in from stdin that is tab delimited. foo 1 foo 1 bar 1 and outputs foo 2 bar 1 Any suggestions for ...
5
votes
1answer
261 views

Enumerate k-combinations in Clojure (P26 from 99 problems)

I've been playing with Clojure for the last few evenings, going through the well known 99 problems (I'm using a set adapted for Scala). Problem 26 calls for a function that, given a set S and a no. ...
7
votes
2answers
728 views

Review my implementation of Viterbi in Clojure?

I would be grateful for suggestions that I use to turn this code into more idiomatic clojure code. I've probably done some pretty horrendous things here, but I'm throwing it out for people to give me ...
7
votes
1answer
360 views

Unix sort in Clojure

I am implementing Unix sort in Clojure. This is my first program, and I would like some feedback regarding any non-idiomatic, harmful code and any other best practices I can include in future ...
2
votes
1answer
149 views

More concise way to write this clojure code adapted from map-invert?

I wanted to do the following: Count the frequencies of words in a text (over 5 letters) Invert the map of words to frequencies, but group together words that have the same frequency in the ...
4
votes
1answer
121 views

Improve this Clojure code to construct a tail cmd?

I wrote this without much thought: (defn- tail-cmd "Construct a tail cmd" [file n & ignore-patterns] (clojure.string/join " | " (flatten [(format "tail -n %s -f %s" (or n 200) file) ...
1
vote
1answer
197 views

Three (do)s in a Clojure method

I'm new to Clojure. How can I make this more idiomatic Clojure code? Among other things, there are three (do) blocks and I don't think using (def) as many times as I do is a recommended idea. (defn ...
4
votes
1answer
241 views

A crude clojure progress reporting function

Please review this newbie's clojure code (mine). The purpose of this function is to report processing progress to the terminal. It loops through an array of maps that contain two properties: ...
3
votes
1answer
190 views

Clojure: lazy look and say sequence

I have been solving a set of online Clojure problems, one of them involves the look and say sequence. I have some working code: (defn look-and-say [s] (let [las (loop [item (first s) coll s ...
1
vote
3answers
98 views

From enumerator to map

I have an mail object that returns its headers as an Enumerator of Header objects, which have two methods, getName and getValue. I need to convert that to a nice Clojure map so I wrote this short ...
6
votes
4answers
313 views

How can I improve this code?

How can I improve this clojure code? It looks strange to me to have two recurs in the if. It solves the following problem. The following text is an in-order traversal of a binary tree with 1023 ...
3
votes
2answers
305 views

How can I improve this code?

The following code solves this problem: The 3072 characters below contain a sequence of 5 characters which is repeated. However, there is a twist: one of the sequences has a typo. To be specific, ...
5
votes
4answers
576 views

Clojure — partitioning strings into substrings of fixed length

Hey all, I've got a clojure function here that's meant to parse a string of form "DDXXXYYY" where DD is meant to be discarded, and XXX and YYY are string representations of integers. Here's my ...

1 2