First, I assume each structure-specific sequences would have different ways to remove an item: Vectors could be by index, List could be remove first or last, Set should be passing of the actual item to remove, etc.
Second, I assume there are some methods for removal that are structure agnostic; they work on seq interface.
Since sequenc...
OK. I've been tinkering with Clojure and I continually run into the same problem. Let's take this little fragment of code:
(let [x 128]
(while (> x 1)
(do
(println x)
(def x (/ x 2)))))
Now I expect this to print out a sequence starting with 128 as so:
128
64
32
16
8
4
2
Instead, it's an infinite loop, printing 12...
Hi.
I'm just wondering if it's possible to create Spring managed beans backed by Clojure code (Clojure namespace I guess, would implement regular Java interface)? If so, the example would be appreciated.
Thanks,
Dmitriy.
...
I've been working on solving Project Euler problems in Clojure to get better, and I've already run into prime number generation a couple of times. My problem is that it is just taking way too long. I was hoping someone could help me find an efficient way to do this in a Clojure-y way.
When I fist did this, I brute-forced it. That was ea...
I'm using Emacs' Clojure mode with SLIME and swank-clojure. I have an issue with the indentation. Most of the time the indentation does what I want: it indents with 2 spaces when I press TAB. But , for example, in the case of a proxy, the indentation I get with TAB is huge: 10 spaces. Example:
(defn- create-frame []
(let [frame (JFram...
I'm dabbling in clojure and am having a little trouble trying to determine the clojure (and / or Lisp) equivalent of this common python idiom.
The idiom is that at the bottom of a python module there is often a bit of test code, and then a statement which runs the code, for example:
# mymodule.py
class MyClass(object):
"""Main logi...
Hi. I realize that the first rule of Macro Club is Don't Use Macros, so the following question is intended more as an exercise in learning Clojure than anything else (I realize this isn't necessarily the best use of macros).
I want to write a simple macro which acts as a wrapper around a regular (defn) macro and winds up adding some me...
The obvious way is to load up JDBC support from Clojure Contrib and write some function to translate a map/struct to a table. One drawback of this is that it isn't very flexible; changes to your structure will require DDL changes. This implies either writing DDL generation (tough) or hand-coding migrations (boring).
What alternatives ex...
I'm trying to get into the Clojure community. I've been working a lot with Python, and one of the features I make extensive use of is the zip() method, for iterating over pairs of values. Is there a (clever and short) way of achieving the same in Clojure?
...
I've been playing a little bit with Arc/Anarki and Clojure lately. But what I really miss is something like mod_arc or mod_clojure for Apache. What I really miss is good Apache integration for a Lispy web language.
Both Arc and Clojure use their own built in webserver that you launch within your code. I want all the functionality, re...
I want to use the value of a variable to compute the value of another variable in the same let statement. Is there a way to do this in Clojure without using nested lets?
Nested let solution:
(let [x 3] (let [y (+ 1 x)] y)) = 4
Desired solution:
(let [x 3 y (+ 1 x)] y) = 4
...
I'm attempting to learn Clojure from the API and documentation available on the site. I'm a bit unclear about mutable storage in Clojure and I want to make sure my understanding is correct. Please let me know if there are any ideas that I've gotten wrong.
Edit: I'm updating this as I receive comments on its correctness.
Disclaimer: A...
My adventures in Java have lead me to look into Clojure, which then lead me to (re)discover Emacs and that lead me to SLIME.
I have a fairly decent handle on Emacs itself, and I have the emacs-starter-kit as well as clojure-mode/slime/swank as well as a few other unrelated modes and tweaks setup and running.
But setting up a program an...
I have Clojure function that takes a sequence of numbers chops it into the appropriate number of bits and returns a lazy sequence of the chunks (lowest order bits first). It pads the high order bits of the last block to fill out the block size and I need advice on the "best way(tm)" to record the amount of padding while keeping it lazy a...
What's the simplest way to create a vector of distinct refs?
Using (repeat 5 (ref nil)) will return a list, but they will all reference the same ref:
user=> (repeat 5 (ref nil))
(#<Ref@16ef71: nil> #<Ref@16ef71: nil> #<Ref@16ef71: nil> #<Ref@16ef71: nil> #<R
ef@16ef71: nil>)
Same result with (replicate 5 (ref nil)):
user=> (replicat...
What's the best way to implement keywords as optional flags to a function?
I want to make function calls such as:
(myfunction 5)
(myfunction 6 :do-this)
(myfunction 3 :go-here)
(myfunction 2 :do-this :do-that)
Using defn, I can define a function such as:
(defn myfunction [value & flags] ... )
But the flags becomes a list. I can wri...
In java i would read the whole file in to byte array and do some processing with it. Now i want to implement the same algorithm in clojure.
What i am wondering is can i use a list instead of an array?
I know i can create array from clojure but what is the lisp way of handling this?
...
I trying clojure i am trying to figure out how to implement the following algorithm,
I am reading from an input stream i want to continue reading until it is not a delimiter character.
i can do this in java with a while loop but i can't seem to figure out how to do it in clojure?
while
read
readChar != delimiter
do some pr...
From googling around, I found that using while loops or using variables is discouraged.
Now I implemented a very simple algorithm that will read characters from an inputstream and parse accordingly: if input is 10:abcdefghej it will parse out 10 then read next 10 bytes after the colon.
The thing I am kinda lost with is how I can refact...
When length is 4 following loop executes 5 times. Reading 5 characters from the stream.
(loop [i (.read stream) result "" counter length]
(let [c (char i)]
(println "=>" c)
(if (zero? counter)
result
(recur (.read stream) (str result c) (dec counter)))))
...