clojure

Problem with passing a vector as a binding to the for macro

I have an arbitrary number of lists which I would like to process using the for macro. I want to create a function that passes a vector as the binding since the number of lists varies. If I hard code the binding, it works as I expect: => (def list1 '("pink" "green")) => (def list2 '("dog" "cat")) => (for [A list1 B list2] (str A "-" B)...

Lazy evaluation problem

Hi, I've a code like this. I can run this in repl but can't from command line. I guess i've a lazy evaluation problem. ; items.clj (def items (ref [])) (defn init-items [] (map #(dosync (alter items conj %)) ["foo" "bar" "baz" ] )) (init-items) (println (first @items)) $ java -jar clojure.jar items.clj $ nil Re...

Lisp code debugging

During web searching, I found the following comment : Traditional Lisp debugging practices can still be used. What are the traditional debugging practices? Normally, what tools are used for debugging lisp (with/without emacs)? ...

How Clojure's agents compare to Scala's actors?

I wrote a simulation of the Ring network topology in Scala (source here) (Scala 2.8 RC7) and Clojure (source here) (Clojure 1.1) for a comparison of Actors and Agents. While the Scala version shows almost constant message exchange rate as I increase the number of nodes in network from 100 to 1000000, the Clojure version shows message r...

Trouble with lazy convolution fn in Clojure

I am writing some signal processing software, and I am starting off by writing out a discrete convolution function. This works fine for the first ten thousand or so list of values, but as they get larger (say, 100k), I begin to get StackOverflow errors, of course. Unfortunately, I am having a lot of trouble converting the imperitive ...

emacs (cocoa emacs) vs aquamacs for running clojure on Mac OS X

I used Aquamacs so far, and I need to install and run clojure using SLIME. I googled to get some way to use clojure on SLIME of Aquamacs, but without success. Questions Does anyone succeed installing clojure on Aquamcs? Or, can you guess why clojure on Aqumac doesn't work? Is it normal that emacs and aquamacs can't share the same ELP...

Compact Clojure code for regular expression matches and their position in string

Stuart Halloway gives the example (re-seq #"\w+" "The quick brown fox") as the natural method for finding matches of regex matches in Clojure. In his book this construction is contrasted with iteration over a matcher. If all one cared about were a list of matches this would be great. However, what if I wanted matches and their positio...

clojure unqoute problem

i have a simple clojure syntax problem (bc i am new to the language). for both examples i have a list lst of (1 2 3 4): in Lisp i can write: =>`(first of list is ,(first lst)) (first of list is 1) in Clojure, if i write the same thing (with the language translation of , to ~ as i THOUGHT i read somewhere) i get: =>'(first of...

Best Practice for globals in clojure, (refs vs alter-var-root)?

I've found myself using the following idiom lately in clojure code. (def *some-global-var* (ref {})) (defn get-global-var [] @*global-var*) (defn update-global-var [val] (dosync (ref-set *global-var* val))) Most of the time this isn't even multi-threaded code that might need the transactional semantics that refs give you. It jus...

How to run clojure on Mac OS X?

I'm following the examples from the book 'Programming Clojure', and I'm at page 17 to run (require 'example.introduction). I have set clojure at ~/bin/clojure as follows java -server \ -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8888 -cp ... clojure.lang.Repl The -cp contains . (current directory). When I ...

Polymorphism in Clojure

Suppose I have a bunch of Clojure data structures, all of the same type - for example an object type defined by defrecord. What is the best way to get polymorphic behaviour across these structures? Would it be good practice to embed a function within the structure so that I can do something like: ((:my-method my-object) param1 param2)...

What is the Clojure equivalent of a "public static final" constant in Java

I'm writing some Clojure code that depends upon a number of constants. They will be used within tight inner loops, so it's important that they will be used and optimised as efficiently as possible by the Clojure compiler+JVM combination. I would normally used a "public static final" constant in Java for the same purpose. What is the be...

How do I write a predicate that checks if a value exists in an infinite seq?

I had an idea for a higher-order function today that I'm not sure how to write. I have several sparse, lazy infinite sequences, and I want to create an abstraction that lets me check to see if a given number is in any of these lazy sequences. To improve performance, I wanted to push the values of the sparse sequence into a hashmap (or se...

Does a Clojure proxy always invoke super.method()?

While using Clojure proxies, fns passed to proxy should override existing methods or are they called in conjunction with super.method()? In the following code, RequestHandler.get() is invoked along with the proxy get []. ;see: http://github.com/paulosuzart/JTornado (ns org.ctornadoweb) (import '(org.jtornadoweb Web$RequestHandler)) (im...

repl is not working(clojure box)

Hello all I want to use syntax highlighting for clojure in emacs + slime + clojure. So I did following step. run clojure box M-x clojure-mode in slime-repl clojure syntax highlighting is success. But repl is not working. I expect a result of 3. But cursor blinks. repl no response. ; SLIME user> (+ 1 2) -K\**_ *slime-repl cloju...

Clojure: No implementation of method in protocol

I am trying to load the Clojure library for RDF clj-plaza in Clojure REPL like so: user=> (use 'plaza.rdf.core) nil I have a folder named plaza, and a subfolder named rdf and the file core.clj available and as far as I can tell, Clojure REPL loads the library as it should. Now, if I do user=> (alter-root-rdf-ns “http://www.example.o...

Has anyone used Incanter in a web app to serve statistical graphs?

I'd like to serve up statistical graphs based on Incanter with a framework like Ring or Compojure in a Clojure environment. I haven't seen any examples or links that do this. Could someone steer me toward working examples? Would Enlive help out here as well? Thanks ...

What is the Clojure equivalent of Ruby's select?

I want to return a list/collection of all numbers in a range that are a multiple of 3 or 5. In Ruby, I would do (1..1000).select {|e| e % 3 == 0 || e % 5 == 0} In Clojure, I'm thinking I might do something like... (select (mod 5 ...x?) (range 0 1000)) ...

Clojure data structure serialization

I have a complex Clojure data structure that I would like to serialize - basically the entire current game state for an online game I am developing so that I can implement save game files. My requirements are: Some form of human-readable text format (I'd probably prefer s-expressions, JSON and XML in that order but open to others) Sup...

Improving clojure lazy-seq usage for iterative text parsing

I'm writing a Clojure implementation of this coding challenge, attempting to find the average length of sequence records in Fasta format: >1 GATCGA GTC >2 GCA >3 AAAAA For more background see this related StackOverflow post about an Erlang solution. My beginner Clojure attempt uses lazy-seq to attempt to read in the file one record a...