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
1
vote
2answers
30 views

Predicate testing for equality that returns the common element

I'm going to try brute-forcing the solving of a Magic Square. To simplify the code later on, I wanted a function similar to =, but one that returns the common ...
2
votes
1answer
131 views

Bloom-filter implementation in Clojure

Background Bloom-filter is a data structure to which we can insert elements, and check if it already contains a given element. The peculiarity is, that if a ...
2
votes
2answers
73 views

Find the middle of the string

The follow code should correctly run the test cases at the bottom. It works correctly. I just don't feel like this is clearest way I could write it. A lot of the complexity comes from having to ...
4
votes
0answers
55 views

Sierpinski Carpet using Seesaw

I decided to write a Sierpinski Carpet generator. This has been something I wanted to try since watching the Coding Train this summer. A screenshot of it in action with some experimental coloring: ...
0
votes
1answer
46 views

Find combinations of items in a nested collection

It's a very typical problem that I come across here and there. Imagine that you have a collection of items of any type, and sometimes items are collections themselves; you then need to "expand" them ...
3
votes
0answers
45 views

SQL-like syntax to sort and filter a collection

I was helping someone on SO with an assignment to create a macro that accepts an SQL-like syntax, and optionally sorts and filters a collection. I realized that while their instructor is insisting on ...
1
vote
0answers
468 views

Infix to RPN converter using the Shunting-Yard Algorithm

I need to be able to parse simple equations in an app I'm writing, and decided to try writing my own parser. I ended up using the Shunting-Yard Algorithm to convert from infix notation to RPN as the ...
2
votes
2answers
69 views

Program follows sequence of instructions to arrive at destination

I'm warming up with Clojure to try my hand at the advent of code challenge that starts in December. This is my attempt at the first challenge from last year. This is my first attempt at a non trivial ...
0
votes
3answers
343 views

Binary search algorithm in Clojure

I'm absolutely new to Clojure (started learning it yesterday). After I went through some tutorials and checked out the basics I implemented the following Binary search algorithm: ...
2
votes
0answers
211 views

Simple client/server library

I'm writing a Tamagotchi clone, and decided to try making an online version. Since I don't do a lot of networking projects, I decided to try and go off on a tangent and screw around with sockets and ...
1
vote
1answer
45 views

Macro that generates a defn

I need to save nested data to disk for a project. Right now, my state is a nested record, and has proven to be a pain to serialize. I tried compressing it to a map, but after testing it, I realized my ...
3
votes
2answers
98 views

Code Chef RAINBOW Palindrome

Problem Determine whether an array is "Rainbow", i.e. it has the following structure: First a1 elements equal 1. Next a2 elements equal 2. Next a3 elements equal 3. Next a4 elements ...
3
votes
1answer
135 views

Flattening a nested record to its leaves

Note, I discovered a bug after I posted this. The current implementation drops any fields that have an associative value, which is not the intended behavior. I'm writing a Tamagotchi clone, and need ...
1
vote
1answer
41 views

Reducing golfed redundancy

For the "First they came" golfing challenge, I wrote the following: ...
5
votes
1answer
184 views

Depth-first Search Non-Reursive Implementation in Clojure

I've created a non-recursive dfs implementation in Clojure. I'm using the wikipedia article on dfs as a guide. I'm very new to Clojure and functional programming in general. Any tips to improve ...
4
votes
1answer
85 views

Picking a random state from a set based on probabilities

I'm writing a Markov Chain implementation, and need to be able to pick a random state from a set of states, where each state has a different probability of being chosen. In my caffeine-high, I wrote ...
2
votes
0answers
184 views

Functional way to handle JMSConnection open and close with Clojure

I wrote this code to automatically open and close my JMSConnection's in Clojure: ...
3
votes
1answer
116 views

One-Dimensional Cellular Automata

First, a teaser with an aweful gif! After watching the first couple minutes of The Coding Train's awesome video on Cellular Automata, I decided to try and write my own. I've written many versions of ...
1
vote
0answers
67 views

Answering Master Clojure for the Brave and True - concurrency exercises

I recently answered the two exercises at the end of this chapter of Clojure for the Brave and True (see the end of the page). First exercise: count words in random quotes (in parallel) This is my ...
1
vote
2answers
246 views

Musical graph algorithm, with an inlined lookup helper function

I am working with bit strings in clojure. My question is less about performance and more about how one should go about it (in particular see the last inlined version) The tonnetz-array represents an ...
1
vote
0answers
161 views

Clojure core.async to handle communication with rabbitmq

I'm learning how to use rabbitmq in the course of writing a webapp in Clojure that will need to call out to Python for occasional machine learning. On the Clojure side, the main library is Langohr, ...
3
votes
1answer
128 views

Monopoly Movement Simulation

A few days ago, I read something to the effect of "everyone knows orange tiles are the most frequently landed on of any property". I was skeptical of this claim, so I decided to test it! This program ...
4
votes
1answer
62 views

Generating lists of sequences of specified lengths

I'm writing a program that uses a Genetic Algorithm to "intelligently brute force" our schedule at work. We typically have issues with creating schedules, so I thought using my new GA library to ...
2
votes
0answers
102 views

Code “beautifier” in Clojure

I've recently made a plugin that "beautifies" code. What it does is lump all the semicolons and curly braces to one side of the program, thus making the code "whitespace-sensitive", and therefore "...
1
vote
0answers
32 views

Map-range supporting different precisions

I'm writing a Mandelbrot Set implementation, and to map the "Mandelbrot" coordinates to screen coordinates, I'm using Quil's map-range function. Essentially, it ...
4
votes
0answers
68 views

Evaluating RPG-formatted dice rolls with repeats in Clojure

My target was to write a function that takes a String as input, interprets it as a series of dice rolls, evaluates it and returns a series of integers. The input is in a form that is typical in table ...
4
votes
0answers
141 views

Attempt at Idiomatic Hangman in Clojure

I am pretty new to Clojure & am loving it so far. After going through a few resources, I decided to make a hangman game. I'm wondering how idiomatic is my code & where can I improve it ...
5
votes
0answers
88 views

Clojure BrainF*** Interpreter

Since I want to try writing my own language at some point, I wanted to have some experience writing an interpreter. BrainFuck is the simplest language I (kind of) know, so I decided to try writing an ...
0
votes
1answer
145 views

Drawing circles with the mouse using Quil+Clojure

I've recently begun using Clojure, and I wanted to translate a project that I wrote with p5.js to us Clojure and quil. Unfortunately, the code resulting from a direct translation is bad enough to make ...
1
vote
0answers
170 views

Transforming between hiccup and enlive/clojure.xml data structures using spec

I've made functions that transform hiccup <-> enlive Example: [:div [:p {:class "foo"} "bar"]] <-> ...
5
votes
2answers
122 views

Bringing Clojure to project Euler 19

I recently began learning Clojure for fun, and after completing the koans, I decide that project Euler would provide my next challenge. Here is the problem statement: (If someone knows how to put ...
2
votes
2answers
269 views

Filtering a data structure using regex predicates

Assume we have a data-structure like this: ...
2
votes
3answers
171 views

Generate a deck of cards in Clojure / Clojurescript

I would like to generate a deck of cards: {:card-id 1 :suit :spade :rank 1} {:card-id 2 :suit :spade :rank 2} ... {:card-id 52 :suit :club :rank 13} And here is ...
3
votes
1answer
128 views

Converting to and from Roman numerals

I wrote a simple Boot script for converting to and from Roman numerals using instaparse. Here's my EBNF grammar (roman.bnf): ...
2
votes
1answer
84 views

Nand gate wiring simulator in clojure

Maybe this is a little large for a simple code review, but I think it included a lot of different needs and how I tried to meet them. Pick a section or function and let me know where I might improve. ...
5
votes
3answers
172 views

Haversine Formula in Clojure

I implemented the Haversine formula to calculate the distance between two (latitude, longitude) coordinates. I was wondering if it looks natural to Clojure programmers. What could be improved? <...
2
votes
2answers
151 views

Code minimizer - Remove unnecessary whitespace

I often do golf challenges, and thought it might be advantageous to write some code that automatically removes all the unnecessary whitespace from a program. After a few refactors, this is what I ...
3
votes
1answer
110 views

Job shop scheduling with Clojure's core.logic

Here's a job shop scheduler using core.logic. I had a lot of fun coding it. I'd appreciate ideas on how to make the code faster or more readable. Setup ...
2
votes
1answer
142 views

Sorting algorithms and command-line interface

I have implemented both some sorting algorithms (namely bubble sort and merge sort), as well as a command-line interface, in ...
2
votes
0answers
111 views

Function to log arguments and return value of any function in Clojure

I have implemented a function, which logs the inputs and outputs of any function, indenting the log based on the depth of the call stack: ...
1
vote
1answer
81 views

Parsing string into hash-map with 2D coordinates as keys

I had never programmed in a functional programming language before. I think that this function has large nesting. Is there way to rewrite it better? I am most worried about the use of "flatten". Is ...
2
votes
1answer
102 views

Incrementing colors

I just started messing around with Java's BufferedImage. I had an idea to try to encode a message into a picture by coloring each pixel a certain color that ...
2
votes
1answer
767 views

Flattening a nested map [closed]

We're migrating our streaming ETL application from Python into Clojure, the hottest part of the code isn't yet performing as well as our existing implementation. This looks to be down to the ...
4
votes
1answer
278 views

Short Clojure digit extraction

I'm new to Clojure, and would appreciate feedback on this short program. The problem I set out to solve was selected at random from Project Euler, and is described in the comments. The part that I'm ...
2
votes
2answers
121 views

Finding the longest path in an equally-weighted tree

Its purpose is to find the longest path in an equally-weighted tree denoted as such: 3 1 2 2 3 The first number denotes both the number of vertices and the ...
1
vote
1answer
88 views

Quicklyish finding primes by trial division

I ask because it seems to be taking waaaay more space/time than it should. Also, I know that if I want to be super efficient I should use Java's BitSet and a Sieve of Eratosthenes, but I wrote it like ...
5
votes
0answers
75 views

Python-style object library for Clojure

Background I am authoring pulley.objective, an Open Source library that provides an object system inspired by Python's object model. I have some features ...
7
votes
1answer
187 views

2048 game implementation in Clojure

This is my first Clojure program. If you want to run it locally please check out https://github.com/achikin/game2048-clj core.clj ...
2
votes
1answer
279 views

Multiple files data processing in Clojure

I have made a small script which grabs data into a map from 80 CSV files and calculates some statistics like average, standard deviation etc. It's also adding some additional data to map from filename....
3
votes
2answers
129 views

Scrape 4chan for alive images

I'm trying to learn Clojure recently and I thought writing a simple web app would be a good way to dive in. This function gets the list of alive threads from the API and reduces, filters and maps ...