clojure

How do I get my brain moving in "lisp mode?"

My professor told us that we could choose a programming language for our next programming assignment. I've been meaning to try out a functional language, so I figured I'd try out clojure. The problem is that I understand the syntax and understand the basic concepts, but I'm having problems getting everything to "click" in my head. Doe...

Problem compiling in Clojure

I've been trying to compile a very simple test.clj in Clojure without any success. I have a thread on the Clojure Google Group with several responses, but nothing has helped. To quickly summarize, here is my clojure file: (ns test.test (:gen-class)) (defn -main [gre] (println (str "Hello " gre))) Basically it's the exam...

How do I connect to a MySQL database from Clojure?

Assumption: you already have both Clojure and MySQL running on your machine. How do you make them talk? ...

let vs def in clojure

I want to make a local instance of a Java Scanner class in a clojure program. Why does this not work: ;gives me: count not supported on this type: Symbol (let s (new Scanner "a b c")) but it will let me create a global instance like this: (def s (new Scanner "a b c")) I was under the impression that the only difference was scope...

Clojure GUI calculator problem. "-" always returns 0 and "/" always returns 1.

I'm well aware this code is horrible. I just made it so I could try out different Swing stuff. This is an interesting problem. This creates 4 buttons one for adding, subtracting, dividing and multiplying. Multiplying and adding works perfectly, no problems at all, but when the user tries to subtract it always returns 0. When the user tri...

Tired of ASP.NET, which of the following should I learn and why?

Which of the following technology is easy to learn and fun for developing a website? If you could only pick one which would it be and why Clojure/Compojure+Ring/Moustache+Ring Groovy/Grails Python/Django Ruby/Rails Turbogear Cappuccino or Sproutcore Javascript/jQuery ...

How do I make a Java class immutable in Clojure?

I'd like to wrap java's PriorityQueue class in clojure for use in another part of my program. What I'm trying to figure out is if there is any way to do this in a lispy manner and make the priority queue immutable. Are there any good ways to do this, or am I just going to be better off using the PriorityQueue as a mutable data structur...

How to defn a function from string in Clojure?

Hi, I'd like to do this (in REPL or anywhere) (defn (symbol "print-string") [k] (println k)) and then be able to do (print-string "lol") Or, if there is any other way to create defn from custom strings in macroses, could you push me into the right direction please? ...

why does "(def vowel? (set "aeiou"))" work?

I'm taking a look at the excellent Clojure tutorial here. In one of the examples it has Clojure code along the following lines: (def vowel? (set "aeiou")) This makes vowel return true for vowels and false for consonants: (vowel? (first "abc")) ; => true (vowel? (first "cba")) ; => false Why is this? I'm assuming it has something to...

Clojure nil vs Java null?

Forgive me if I'm being obtuse, but I'm a little bit confused by the documentation about nil in Clojure. It says: nil has the same value as Java null. Does this mean that they're the same thing or are they different somehow? And does a NullPointerException mean that a Java null was encountered or would I also get this if nil was ...

Clojure keyword arguments

In Common Lisp you can do this: (defun foo (bar &key baz quux) (list bar baz quux)) (foo 1 :quux 3 :baz 2) ; => (1 2 3) Clojure doesn't have keyword arguments. One alternative is this: (defn foo [bar {:keys [baz quux]}] (list bar baz quux)) (foo 1 {:quux 3 :baz 2}) ; => (1 2 3) That's too many nested brackets to have to typ...

how to parse binary files in Clojure

What is the cleanest way to parse binary data in clojure? I need to be able to read/write equally cleanly to a file or a socket. something like: (read-data source-of-data) => { :index 42 , :block-size 4 , data-size: 31415, :data (1 2 3 4 ...)} and the reverse for putting data back. It would be really great to somehow define t...

How can I leak memory in Clojure?

For a presentation at the Bay Area Clojure Meetup on Thursday I am compiling a list of ways to leak memory in Clojure. So far I have: hold onto the head of an infinite sequence creating lots of generic classes by calling lambda in a loop (is this still a problem) holding a reference to unused data ... What else? ...

In a Emacs + Slime + Clojure + Windows setup, failure to load clojure-auto

I followed this very helpful guide on getting this development environment set up. When running the emacs.bat I get the following error in Emacs: File error: Cannot open load file, clojure-auto Unfortunitely I am completely new to both Clojure and Emacs, so any help in even figuring out where to begin looking would be helpful. Als...

How to start Java from within a C process?

I want to add some Java (actually Clojure) based event handlers to a HUGE legacy C application. What is the most straight forward and easily maintained way to do this? I would like the Java classes to be running in the same process as the C code. Is this even possible? ...

How well does Programming Clojure work on the Kindle?

Programming Clojure is currently available only in electronic form. I see it's available in .mobi format for the Kindle. My question is, how well does this work? I know some programming books can lose the formatting of the code on the Kindle. Has anyone tried this? Does this version work well? ...

use vs. require in Clojure?

Can anyone explain the difference between "use" and "require", both when used directly and as :use and :require in the ns macro? ...

Weird Clojure Box - library (dll) issue

I am trying to use the JACOB library with Clojure using Clojure Box. I have added this to my .emacs: (setq swank-clojure-library-paths (list "c:/dev/dlls")) C:/dev/dlls/ contains the jacob-1.14.3-x86.dll. I have added a .clojure dir to my ~/ dir and that contains the jacob.jar. At the Clojure Box REPL, (System/getProperty "java.cl...

F# vs. Clojure

What are the most significant differencies between the F# and Clojure ? Which constructs has F# which Clojure does not have and vice versa? Does F# have macros? ...

Clojure: slurping structs from file fails with string attributes containing whitespaces

Hi. I have just started playing with Clojure and the first thing I thought I'd try is storing and retrieving a list of structs, like in Suart Halloway's example here. My spit/slurp of a hash of structs works fine with, if I use struct instances without spaces in the attribute strings like the following: (struct customer "Apple" "Infin...