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.
309
questions
5
votes
3
answers
149
views
Adding augmented maps to a vector based on regex text grabbing
This is my latest brain child for clojure, could it be done with less code, cleaner, or in a more re applicable way? I am at a pretty early stage in my clojure learning so an in depth explanation of ...
5
votes
2
answers
218
views
Implementing parser combinators in a functional manner
I am just starting on my journey of learning clojure (I have just read to the end of chapter 3 in clojure for the brave and true). So for practice, I wrote some parser combinator functions. I am quite ...
5
votes
1
answer
179
views
A text-templating system similar to PHP...but with Clojure
I wrote a simple text-templating/processing system which resembles PHP, except that it works with Clojure. The main goal was to provide an easy way to use Clojure PHP-style for small files.
This is a ...
5
votes
1
answer
340
views
A* in Clojure - trickier than I expected
While working through some coding puzzles to brush up on Clojure, I encountered the need to use A* on some search problems. I tried to implement it from first principles/memory and that didn't go ...
5
votes
2
answers
690
views
Number of ways to make change for an amount
Task
Write a program that, given the amount to make change for and a list of coins prints out how many different ways you can make change from the coins to STDOUT.
My approach
The number to make ...
5
votes
1
answer
162
views
Creating and displaying a checkers board
I am learning clojure this week end and just starting to develop a simple checkers engine. I currently coded some basic functions to create the board and display it. I would love to get some feedback !...
5
votes
1
answer
128
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?
...
5
votes
2
answers
769
views
Parsing infix expressions in Clojure
I'm trying to teach myself Clojure by reading the Brave Clojure book online, and at the end of Chapter 7 there is an exercise to parse a mathematical expression written as a list in infix notation to ...
5
votes
2
answers
146
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 ...
5
votes
1
answer
388
views
A very simple TODO app's domain model
I am currently rewriting a todo app from java to clojure. This is my first "real" clojure project so I'm not sure that what I write is idiomatic clojure code. I have just finished rewriting the domain ...
5
votes
1
answer
116
views
Selecting HTML nodes
I'm new to Clojure, and I'm writing some code that processes HTML. I'm parsing the HTML using clj-tagsoup and then trying to pull out the relevant bits with this function:
...
5
votes
1
answer
109
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 ...
5
votes
1
answer
337
views
Second to last word
Grab the input file, and output the second to last word on every line.
Can I make it shorter and/or more efficient?
I'm surprised by the performance. While the runtime, +2s, is likely dominated by ...
5
votes
1
answer
281
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?
...
5
votes
1
answer
188
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, ...
5
votes
1
answer
2k
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 ...
5
votes
1
answer
171
views
Constructing a tail cmd
I wrote this without much thought:
...
5
votes
1
answer
405
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 ...
5
votes
2
answers
139
views
Resolve double auction orders
Given a vector of seller orders (asks) of a certain product (each order having a price) and buyer orders (bids) of the same product, I'm creating a function that resolves the auction by matching the ...
5
votes
1
answer
518
views
Shuffle a deck of cards, using the overhand shuffle method
I've started learning Clojure, after many years of Java. As one of a series of exercises, I'm writing a simple card game, and the overhand-shuffle function is shown ...
5
votes
1
answer
553
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 ...
5
votes
1
answer
255
views
Hackerrank: Breaking the records
I'm learning Clojure and am a rank n00b at it, trying to learn from books and online tutorials (but I'm sometimes concerned that I am picking up bad habits or at least not all the good habits). For ...
5
votes
2
answers
293
views
RSS feed viewer in Clojure
This semester a classmate and I visited a course on functional programming in our university. For grading, we've to submit a small project which should be written in Clojure and make use of functional ...
5
votes
0
answers
110
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 ...
5
votes
0
answers
88
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 ...
4
votes
3
answers
333
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 ...
4
votes
2
answers
254
views
Clojure performance for solving Project Euler 72 (counting proper reduced fractions)
Challenge
This is a solution of Project Euler 72 in Java.
How may proper reduced fractions \$\dfrac{n}{d}\$ are there, where \$n
< d \le 10^6\$?
Code
...
4
votes
2
answers
916
views
Dijkstra's algorithm in Clojure
I'm learning Clojure and I'm interested in areas that could be more idiomatic. The main function is below. If you're interested in the whole lib, check out this.
The function operates on a ...
4
votes
3
answers
235
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. ...
4
votes
3
answers
490
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
...
4
votes
1
answer
1k
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
2
answers
245
views
Centroid of a polygon in Clojure
I am studying Clojure and functional programming. I wrote this function to compute the centroid of a polygon specified as a vector of points, e.g. ...
4
votes
1
answer
104
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 ...
4
votes
1
answer
1k
views
Higher-order FizzBuzz in Clojure
Help me make it better. Requirement: support arbitrary number of factors, not just 3 & 5.
...
4
votes
1
answer
484
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
2
answers
127
views
Extract indices of visible nodes in a tree where only some nodes are expanded
A program that I work on constantly updates and modifies program state containing an arbitrarily deep and wide tree. The data looks something like this.
...
4
votes
1
answer
494
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 ...
4
votes
1
answer
210
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 ...
4
votes
3
answers
283
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.
...
4
votes
1
answer
224
views
Generating two .csv files from named parameters
I wrote Clojure code which takes named params and has to generate 2 .csv files as output.
Please review it.
...
4
votes
1
answer
354
views
Calculating Pi in Clojure
Obviously there are better ways of obtaining Pi, but for educational purposes, how is the code below?
...
4
votes
1
answer
73
views
Langton's ant in Clojurescript
The weekly coding challenge in Eric Normand's newsletter this week involves implementing Langton's ant.
I wanted something on my screen so I put together a simple re-frame app. The core functions ...
4
votes
1
answer
105
views
Building blocks of Life
I'm learning Clojure, and decided to write a Conway's Game of Life clone as my starting project. I ended up dicking around for a bit before diving in, and came up with a few functions that I'd like ...
4
votes
1
answer
264
views
Clojure word count
I'm fairly new to Clojure and looking to improve my use of the proper idioms, and make my code more readable. Here's the problem:
Read from standard input and produce the count of each word to ...
4
votes
1
answer
495
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
1
answer
145
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:
...
4
votes
2
answers
158
views
Clojure function composition: logging results of an action performed by a "pure" function
I'm wondering how I could compose this program better allow it to grow more functionality without constant refactoring.
This is my code sample for Hacker School, so I'm less married to the results ...
4
votes
1
answer
373
views
Project Euler Problem 14 in Clojure
I recently began learning Clojure. In order to get better acquainted with it, I've been tackling Project Euler challenges.
Problem 14 is not really a difficult one. It asks for the number that ...
4
votes
1
answer
228
views
Exercism assignment for word-count in Clojure
I would appreciate some insights / comments from Clojure regulars out there about my submission here.
...
4
votes
2
answers
131
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.
...