Questions tagged [clojure]

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 constructs.

Filter by
Sorted by
Tagged with
10
votes
1answer
970 views

Idiomatic clojure code in a markdown parser

Some time ago I created a markdown parser in clojure and I would like to get some feedback, since I'm a clojure noob in the first place (is the code understandable?/is it idiomatic?/can some things be ...
3
votes
1answer
2k views

Idiomatic input parsing in clojure

I've been playing around with Clojure for a while now, and one of the tasks I occasionally find awkward is parsing input. For example, I took part in the facebook hacker cup recently, where part of ...
9
votes
1answer
3k views

Clojure - substring? function

Trying to write a substring function in Clojure. I am sure there is a more idiomatic way. Can anyone enlighten me? Otherwise, here is my version. Thoughts? ...
5
votes
1answer
253 views

Hangman - my first Clojure code

This is my first attempt at Clojure! Apart from all game related issues, how is my code? Is there anything I can do to make it more idiomatic? ...
10
votes
1answer
1k views

Clojure tokenizer

Please review the following Clojure tokenizer. The goal is to study Clojure, so sometimes I re-implement functions (it will be nice to see standard functions for this). Beyond of this, code seems ...
3
votes
1answer
153 views

Clojure function greater than 10 SLOC

It has been mentioned in the Clojure Style guide to avoid functions longer than 10 SLOC but mine has more than 10 (47 to be exact). The code is an web api implementation and follows like this: ...
1
vote
2answers
1k views

Clojure code for finding prime numbers

This is my Clojure code for finding prime numbers. Note: this is an advanced version which starts eliminating from i*i with step ...
4
votes
1answer
386 views

API wrapper for Clojure

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 ...
48
votes
1answer
2k views

Connect Four AI (Minimax) in Clojure

I wrote a Connect Four game including 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 ...
3
votes
1answer
1k views

Atomically incrementing a value in a map in Clojure

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
461 views

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 ...
3
votes
0answers
288 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
1k views

Mergesort implementation in Clojure

...
4
votes
2answers
114 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. ...
7
votes
1answer
671 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. ...
3
votes
0answers
188 views

Back-propagation implementation

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; ...
2
votes
1answer
339 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. ...
3
votes
1answer
404 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 ...
3
votes
1answer
93 views

Check for the presence of multiple files

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 ...
3
votes
1answer
513 views

Inverted index in Clojure - performance vs. idiomatic code

I have this code to create an inverted index from a directory of text files: ...
14
votes
0answers
406 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 ...
4
votes
1answer
263 views

Calculating Pi in Clojure

Obviously there are better ways of obtaining Pi, but for educational purposes, how is the code below? ...
5
votes
1answer
182 views

Pile shuffle of a vector

My goal is to simulate a Pile shuffle of a vector. It takes 2 optional arguments for the number of piles to use and how many times to perform the shuffle. As this is my first attempt at clojure code, ...
2
votes
1answer
507 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 ...
1
vote
2answers
99 views

Idiomatic letterpress cheater

I need some guidance on making the following code more idiomatic: ...
4
votes
1answer
114 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? ...
6
votes
4answers
426 views

Counting ways to form an amount using coins

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 ...
5
votes
3answers
651 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 (e....
2
votes
1answer
187 views

Idiomatic text munging in Clojure

In getting accustomed to Clojure syntax, I wrote the following stutter function: ...
3
votes
2answers
2k 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
294 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 / ...
7
votes
1answer
2k 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 ...
4
votes
1answer
840 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
386 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, ...
3
votes
1answer
186 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? ...
3
votes
1answer
420 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 ...
8
votes
1answer
289 views

Expanding a map into an infinite sequence

I have a map that I want to 'expand' into an infinite sequence in the following manner: ...
4
votes
1answer
1k views

Higher-order FizzBuzz in Clojure

Help me make it better. Requirement: support arbitrary number of factors, not just 3 & 5. ...
4
votes
3answers
3k 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 ...
8
votes
2answers
1k views

Powerset in Clojure

I think I have correctly implemented Powerset in Clojure. ...
7
votes
1answer
734 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 ...
8
votes
1answer
358 views

Bayesian approximation method for online ranking

I've implementing the this algorithm in Java, Scala, and Clojure to show my teammates. I know the code works as expected. What I'm looking for is tips on good Clojure style. ...
3
votes
1answer
304 views

Simple word translator taking advantage of Wikipedia

This is 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 ...
4
votes
3answers
469 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 ...
5
votes
1answer
1k 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 Given a set S and a no. of items K, returns ...
8
votes
2answers
1k views

Using Viterbi algorithm to analyze sentences

I've probably done some pretty horrendous things here, but I'm throwing it out for people to give me some feedback that I can start using to immediately improve my Clojure coding style. Additional ...
7
votes
1answer
499 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 versions....
2
votes
1answer
220 views

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 inversion....
5
votes
1answer
158 views

Constructing a tail cmd

I wrote this without much thought: ...
2
votes
1answer
301 views

Web service to add a phone number with SMS validation

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. ...

1
3 4 5
6
7