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 ...
0
votes
0answers
13 views
Apply a function to either an element or a collection in Clojure [on hold]
I have a small snippet of code that I use in some places in my program. It applies a function for secondary effects to either a single element or a collection. Given a function ...
1
vote
1answer
20 views
Capping values in a map while keeping one fixed
I'm working with some Clojurescript code that reacts to user input over three sliders. These sliders get stored in a map, and I need to make sure that the sum of all is <= a ...
3
votes
1answer
45 views
Converting Between Clojure Maps and Lists
In an attempt to learn better functional programing I've attempted to convert some Python to idiomatic Clojure, but I'm not sure how well I did with parts of it.
One thing I found myself doing a lot ...
4
votes
0answers
35 views
Dining Philosophers Problem in Cojure
I have implemented the Dining Philosophers Problem in Clojure with refs, trying to emphasize readability. Please point out if parts of it are inefficient, not idiomatic, or improvable in any way. Full ...
6
votes
3answers
88 views
Number of Chocolates to Gluttonize in Clojure
I’ve been dabbling in Clojure by solving programming puzzles. This particular puzzle is from HackerRank, with the objective of figuring out how much chocolate one could eat given three parameters:
...
4
votes
1answer
59 views
Number guessing game in Clojure
I have recently started learning Clojure, and decided to write a number-guessing-game as an exercise.
The game works as follows:
User enters minimum and maximum values
Computer generates a number ...
4
votes
1answer
49 views
Brainfuck interpreter in Clojure
I'm currently learning Clojure to try to get a good understanding of functionnal programming, so I wrote this brainfuck interpreter that takes a filename on the command line. I tried to make it as ...
1
vote
2answers
45 views
Simple Grid Builder for Future Maze Applications
I'm new to Clojure and decided to read the book, "Mazes for Programmers". My first task, without reading any of the book, was to think of how I would create a maze. This is my first result and I'd ...
4
votes
0answers
29 views
Basic declarative style to rotate and crop an image array
I wrote a couple of basic Clojure functions (practicing a declarative style) and I was looking to get some feedback on them. You can see all the code here. Is there anything I could improve on to ...
2
votes
2answers
31 views
Incremental accumulator by subvectoring
The purpose of the following code is to, given a vector, compute the two accumulators: 1. head-till-nth element, 2. (n+1)th element-till-last (where n, and this is the catch, iterates from 1 till ...
2
votes
2answers
57 views
Structure of parser in Clojure
I'm working on my first Clojure project, which is a parser. Since it's my first project I'm unsure of many aspects, from my general approach to solving this problem to the small implementation ...
1
vote
0answers
66 views
A* search algorithm in Clojure
Cost of nodes are represented by a matrix (called world), heuristic cost estimate/g score/f score are all represented in matrices.
The world and its size are ...
3
votes
1answer
66 views
Remove “lines” from a 2D vec
I have some code here that I am very unhappy with. The task I am trying to accomplish is this.
Given a 2d vec like this:
[[0 2 0] [1 3 5] [3 3 0]]
which can ...
5
votes
1answer
61 views
Designing a circuit of gates in Clojure and doing forward and backpropagation
I am reading Hacker's guide to Neural Networks. Since I am also learning Clojure, I tried to implement them in Clojure.
I would like the feedback about what could be more idiomatic and better in the ...
1
vote
1answer
75 views
Managing state in Clojure
Where should you store state and how should it be managed in a ClojureScript application? Take the following code for example - it's a "game" where you travel either down or left.
...
5
votes
1answer
111 views
Starting a Clojure Chess Engine
In my journey to learn Clojure I recently decided that I would like to write a chess engine, which is kind of funny because I don't really know chess either. ;-) My goals are to learn Clojure and ...
1
vote
1answer
159 views
Simple, functional URL parsing library in Clojure
I recently wrote some code to handle parsing of URLs, even if those URLs might not be one hundred percent perfectly well-formed. (This constraint made using Java's ...
0
votes
0answers
29 views
Sieve of Eratosthenes in Clojure
I am mainly interested in how to make the sieve lazy so that it will receive something like (iterate inc 2) and generate an infinite sequence of primes, but any ...
2
votes
0answers
68 views
0
votes
1answer
50 views
Multitenant Cassandra Query in Clojure
The following code handles querying for user data in a multitenant Cassandra database. Each tenant has their own keyspace and within that keyspace data about each tenants users is stored.
This code ...
4
votes
0answers
31 views
Perform a contains-ignore-case with multiple search-tokens
I had a look on Stack Overflow etc. on how to perform a contains ignore case with n given strings. Most answers suggested using regex for this task. Although it's a valid option, I prefer doing ...
1
vote
1answer
58 views
Read Space Delimited Text File to Standardized Data Type
From the README.md
Introduction:
The purpose of data-in is to read all the lines from a text file and return the file's contents as a Clojure value in a ...
10
votes
1answer
81 views
A port of the 1971 StarTrek game to Clojure
I ported the Star Trek 1971 game to Clojure to help me learn more about the language and functional programming in general. You can see the entire game on Github. The game plays (you can start it with ...
1
vote
1answer
33 views
Getting data from different services
I have a piece of code that tries to get some data from a different services, falling back to the next one if previous fails.
The code look a little bit ugly, though. Any suggestions on how to ...
6
votes
2answers
140 views
Water pouring challenge
I'm trying to write code to solve water pouring problem in Clojure. The following code is strongly influenced by Martin Odersky's solution lectured in his coursera course, Functional Programming ...
1
vote
1answer
39 views
Using atom to reference state in Clojure
I am trying to implement a 2D fighting game in Clojure both for fun and learning.
Since the characters in a fighter game are essentially state machines, I constructed the following code:
...
2
votes
1answer
54 views
Encrypting messages using the XOR operation
recently I've started to learn Clojure. I came up with an easy programming problem, described by this C code:
...
-2
votes
1answer
101 views
Clojure koans 14 - converting a map to a string
The koan is at the end of this snippet. It requires you to write a function to convert a map to a string, and then prepend a full name to it.
The following solution works fine. I am just wondering if ...
1
vote
0answers
69 views
Re-implementation of Caolan McMahon's parallel and map functions
I have wrote my first reasonably complete piece of ClojureScript code and would like feedback. It is basically a re-implementation of Caolan McMahon's parallel and
map functions from async in ...
3
votes
1answer
55 views
Getting rid of extra test during initialization of loop/recursion
I'm reluctant to ask this question. My code below works, it's intelligible, and it seems reasonably efficient. It's just that there's a trivial, nitpicky issue that's driving me crazy. The function ...
4
votes
1answer
297 views
Clojure Fibonacci
I'm a Clojure novice working through 4Clojure problems. In one problem I am supposed to create a function that takes a number and returns that number of Fibonaccis. My first thought was to create a ...
4
votes
1answer
76 views
Encapsulated state in clojure
While going through SICP and trying to implement the code in clojure, I've found that while I can get the code in chapter 3 to work, it seems to go against Clojure idioms, but I can't quite imagine ...
1
vote
1answer
63 views
Parsing HTML, XML into a hash map of products
I'm working on a simple parser that is supposed to extract hash maps representing vinyl records from web pages (online stores) and XML files. The goal is to have a parser that I can easily run with ...
3
votes
2answers
172 views
Clojure solution to HackerRank Challenge 'Restaurant' under Number Theory
My main concern is how messy the min-number-of-slices function is. I would appreciate help finding good ways to clean that up since it has a lot of nesting/scope.
...
1
vote
1answer
69 views
Determine if braces in a string are balanced in Clojure
I'm currently learning Clojure, and am working through a few exercises. The exercise that I'm working on right now is accept an arbitrary string and determine if the opening and closing parenthesis, ...
3
votes
1answer
54 views
4
votes
3answers
112 views
Clojure programming exercise for calculating change
I'm learning Clojure and have written a small function to calculate change. I don't like few things about the code and would primarily like to replace recursive call with something more idiomatic. ...
2
votes
3answers
87 views
Memorable combinations for Sargent mechanical combination locks
I have a safe with a manual combination lock that I periodically change the combination to. I like to use a combination that's easy for me to remember, so I thought I'd write a quick Clojure program ...
3
votes
0answers
172 views
Idiomatic way to implement `tail -f` in clojure
Disclaimer: This is just an educational task to learn how to program in clojure and switch brain to immutable state-way of developing (the provided snipped has some unused variables which I didn't ...
2
votes
2answers
228 views
Computing pairwise bitwise OR in a list of bit-strings
I am trying to solve this problem using Clojure:
You are given a list of \$N\$ people who are attending ACM-ICPC World
Finals. Each of them are either well versed in a topic or they are
not. ...
1
vote
2answers
46 views
Split every vector in a sequence into two parts: old elements that were contained in previous vectors and new elements never before seen
Am I doing it right? Is there some function in the standard library I should be using? This is my first real(ish) world Clojure program…
Input
...
5
votes
2answers
128 views
Performing an algebraic regression on syntax trees
I am quite new to Clojure and would need some advice on the following genetic programming gist I wrote as my first working clj program. The aim of it is to perform an algebraic regression using ...
3
votes
2answers
120 views
Clojure Tic Tac Toe solver
I am going through the 4clojure problems and I currently just solved the Tic Tac Toe analyzer:
...
6
votes
1answer
535 views
Clojure core.async web crawler
I'm currently a beginner with clojure and I thought I'd try building a web crawler with core.async.
What I have works, but I am looking for feedback on the following points:
How can I avoid using ...
10
votes
1answer
188 views
Project Euler #2 - Sum of even Fibonacci numbers to 4,000,000
This particular problem has already been posted here before, but the community is ok with me to post it again, so I can have feedback on my own implementation.
I tried to keep things simple, with ...
2
votes
1answer
50 views
Recreating merge-with
Just working through the questions on 4Clojure as I learn the language. This is my solution for #69. Would appreciate feedback as this one gave me a little trouble.
...
4
votes
1answer
64 views
Zeckendorf numbers the Clojure way
I'm just getting into Clojure, and I wanted to make sure I am writing code the "Clojure way". The challenge I took on is Zeckendorf numbers (fairly trivial).
...
1
vote
1answer
57 views
5
votes
1answer
143 views
Algorithm to Iterate All Possible Strings in Clojure
I'm fairly new to Clojure and I struggled a bit coming up with a nice Clojure-y solution for implementing an algorithm for one of my applications. The real issue I'm trying to solve would require a ...
4
votes
3answers
107 views
Parsing US address with Clojure
The parser below is not designed for every single US address. I am parsing through a file where each line may or may not be an address. I am more focused on speed rather than robustness.
...