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
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
423 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
283 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
112 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
666 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
186 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
324 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
397 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
92 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
498 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
395 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 ...
3
votes
1answer
243 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
179 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
494 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
98 views

Idiomatic letterpress cheater

I need some guidance on making the following code more idiomatic: ...
4
votes
1answer
112 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
414 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
632 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
184 views

Idiomatic text munging in Clojure

In getting accustomed to Clojure syntax, I wrote the following stutter function: ...
3
votes
2answers
1k 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
277 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
812 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
381 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
178 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
414 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
288 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
733 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
342 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
303 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
463 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
498 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
216 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
157 views

Constructing a tail cmd

I wrote this without much thought: ...
2
votes
1answer
299 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. ...
4
votes
1answer
443 views

A crude clojure progress reporting function

The purpose of this function is to report processing progress to the terminal. It loops through an array of maps that contain two properties: :sequence and ...
4
votes
1answer
269 views

Lazy look and say sequence

I have been solving a set of online Clojure problems. One of them involves the look and say sequence. ...
2
votes
3answers
180 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
3answers
363 views

Finding the sum of the digits appearing in the leaves via in-order traversal

The following text is an in-order traversal of a binary tree with 1023 nodes. What is the sum of the digits appearing in the leaves? How can I improve this Clojure code? It looks strange to me to ...
3
votes
2answers
404 views

Searching for repeated characters in a sequence of characters

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 ...
7
votes
3answers
2k views

Partitioning strings into substrings of fixed length

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. ...
12
votes
3answers
507 views

Reservoir Sampling in Clojure

I am learning clojure and decided to start out by trying to write a solution to a fairly simple algorithm, reservoir sampling. As I stated, I am learning clojure specifically and problem solving in a ...
23
votes
3answers
2k views

Project Euler Problem 2 in Clojure

I am in the process of learning Clojure. I am fairly new to functional programming and would like to know if my code smells or if there are any performance implications with my approach. ...