Given a list of names for variables, I want to set those variables to an expression.
I tried this:
(doall (for [x ["a" "b" "c"]] (def (symbol x) 666)))
...but this yields the error
java.lang.Exception: First argument to def must be a Symbol
Can anyone show me the right way to accomplish this, please?
...
Which lesser-known but useful features of Clojure do you find yourselves using? Feel free to share little tricks and idioms, but try to restrict yourselves to Core and Contrib.
I found some really interesting information in answers to these similar questions:
Hidden features of Haskell
Hidden features of Python
Hidden features of Java...
I'd like to be able to define lambdas using common Lisp syntax, in Clojure. For example:
(lambda (myarg)
(some-functions-that-refer-to myarg))
This needs to result in the same as:
#(some-functions-that-refer-to %)
In my case, I know I'll always have exactly one arg, so perhaps that simplifies things. (But it can be called anythin...
I'm calling the twitter4j library using Clojure like so:
(def twitter (. (TwitterFactory.) getInstance))
This works fine when I call it as a script. But when I use gen-class, I get:
java.lang.IllegalArgumentException: Can't call public method of non-public class: public java.lang.Object twitter4j.TwitterFactoryBase.getInstance()
I...
Update
As suggested by many people, it looks like this was because of the fact that clojure code was first compiled and then executed. AOT compilation should help offset that. Given I found the practical Clojure AOT compilation process a little tricky to solve (classpath issues, directory issues et al), I've written up a small step by s...
I suspect that calls from separate threads (>15) are having a negative effect on performance. Is there a better way to get at the system time in concurrent applications?
...
Hello!
I'm writing a little parser in clojure for learning purpose.
basically is a TSV file parser that need to be put in a database, but I added a complication.
The complication itself is that in the same file there are more intervals.
The file look like this:
###andreadipersio 2010-03-19 16:10:00### ...
Are the square brackets around arguments in Clojure's defn, defmacro and binding (am I forgetting some?) really creating a vector or is it just a matter of syntax, making the arguments stand out from the rest?
I'm reading Clojure in Action which states:
Clojure uses vectors to denote
function arguments or binding forms.
which m...
I'm trying to get up an running using http://github.com/rnewman/clj-apache-http
(http/get (java.net.URI. url)
:headers {"User-Agent" user-agent}
:parameters (http/map->params
{:default-proxy (http/http-host :host "localhost"
:port 8888)})
:as :string)
Problem is...
Is there a Clojure example of the day kind of service, like a blog, or Twitter account I can follow? Would be really nice to have a short example every day to enhance Clojure skills and to get inspired to delve deeper into the language. Clojure really lends itself well for short but powerful code.
...
What are useful Clojure learning resources that you have used so far? Blogs, tutorials, documentation, books, list them in this community wiki!
...
Hello! I am working on a MUD client written in Clojure. Right now, I need two different threads. One which receives input from the user and sends it out to the MUD (via a simple Socket), and one that reads and displays output from the MUD, to the user.
Should I just use Java Threads, or is there some Clojure-specific feature I should be...
What I would like to do (in Clojure):
For example, I have a vector of words that need to be removed:
(def forbidden-words [":)" "the" "." "," " " ...many more...])
... and a vector of strings:
(def strings ["the movie list" "this.is.a.string" "haha :)" ...many more...])
So, each forbidden word should be removed from each string, a...
i had very nice dev. env. - clojure, maven and jetty with hot deploy. now i moved to google appengine and i can not figure out how to configure maven achieve hot deploy
...
What do you lose in practice when you choose a statically-typed language such as Scala (or F#, Haskell, C#) instead of dynamically-typed ones like Ruby, Python, Clojure, Groovy (which has macros or runtime metaprogramming capabilities)? Please consider best statically-typed languages and best (in your opinion) dynamically-typed languages...
When and where do you put type annotations in Clojure code? Obviously when performance counts. But are there rules by which you can live of when (only when doing Java Interop?) and where to add them (function definition arguments)?
...
Is there a good algorithm to calculate the cartesian product of three seqs concurrently in Clojure?
I'm working on a small hobby project in Clojure, mainly as a means to learn the language, and its concurrency features. In my project, I need to calculate the cartesian product of three seqs (and do something with the results).
I found t...
In F#:
> let f x = x + 2;;
val f : int -> int
> let g x = f x;;
val g : int -> int
> g 10;;
val it : int = 12
> let f x = x + 3;;
val f : int -> int
> g 10;;
val it : int = 12
In Clojure:
1:1 user=> (defn f [x] (+ x 2))
#'user/f
1:2 user=> (defn g [x] (f x))
#'user/g
1:3 user=> (g 10)
12
1:4 user=> (defn f [x] (+ x 3))
#'user/f...
I have been a Java developer for 14 years and have written an enterprise-level (~500 kloc) Swing application that uses most of the standard library APIs. Recently, I have become disappointed with the progress that the language has made to "modernize" itself, and am looking for an alternative for ongoing development.
I have considered mo...
I know that Lisp and Scheme programmers usually say that eval should be avoided unless strictly necessary. I’ve seen the same recommendation for several programming languages, but I’ve not yet seen a list of clear arguments against the use of eval. Where can I find an account of the potential problems of using eval?
For example, I know ...