Aw: Re: Handling java streams..

2011-06-28 Thread Meikel Brandmeyer
Hi, Am Montag, 27. Juni 2011 23:50:52 UTC+2 schrieb Ken Wesson: a) it isn't found by searching the docs in many of the usual ways; Is that really so hard? http://clojure.github.com/clojure top-right TOC: clojure.java.io If I look for stream handling, wouldn't that sound interesting? Sadly

Mocking framework

2011-06-28 Thread Erik Bakstad
Hi, I'm currently working on my first real Clojure project, and I find myself wanting a mocking tool. So I was wondering what you are using? I tried googling, but I can't seem to find the Mockito of the clojure world. Searching for a mocking tool in Clojure it looks like there is a lot of small

Re: struct sharing same key?

2011-06-28 Thread Stefan Kamphausen
Hi, maybe Ken's solution needs some clarification 1. Use a map, not a struct. defstruct is kinda deprecated. 2. Use a keyword (preceded by a colon) to code the nationality. A keyword is created only once and won't consume any more memory if you use it repeatedly. I'm not sure whether you

Re: [ANN] emacs-clojure-vagrant: a sane development virtual environment

2011-06-28 Thread isaac praveen
Justin, Sorry about the missing link. Github upload had some issues with Chrome and hence took a while for me to update the latest jark-0.3 binary. It is up now: https://github.com/downloads/icylisper/jark/jark-0.3 -- isaac http://icylisper.in -- You received this message because you are

Re: Mocking framework

2011-06-28 Thread Ola Ellnestam
Hi Erik, Take a closer look at Midje, especially https://github.com/marick/Midje/wiki/Metaconstants I'm not an subject matter expert but to me it's close enough to mocking/stubbing. Cheers, Ola Erik Bakstad skrev 2011-06-28 08:56: Hi, I'm currently working on my first real Clojure

Re: Mocking framework

2011-06-28 Thread gaz jones
jay fields has a good blog post on this: http://blog.jayfields.com/2010/09/clojure-mocking.html On Tue, Jun 28, 2011 at 2:52 AM, Ola Ellnestam ola.ellnes...@agical.se wrote: Hi Erik, Take a closer look at Midje, especially https://github.com/marick/Midje/wiki/Metaconstants I'm not an

Re: Mocking framework

2011-06-28 Thread László Török
...and a classic (not clojure specific) http://codebetter.com/gregyoung/2008/02/13/mocks-are-a-code-smell/ (Disclaimer: I don't necessarily share Greg's opinion, but interesting nonetheless) 2011/6/28 gaz jones gareth.e.jo...@gmail.com jay fields has a good blog post on this:

Best Way To Extract Data From Lazy Sequence

2011-06-28 Thread octopusgrabbus
Given this test program: (ns test-csv (:gen-class) (:use clojure.contrib.command-line) (:use clojure-csv.core)) (defn process-file Process csv file and prints first item in every row [file-name] (let [data (slurp file-name) rows (parse-csv data)] (dorun (map #(println

Re: Best Way To Extract Data From Lazy Sequence

2011-06-28 Thread Alex Robbins
If you are trying to get the 6th row, you might use the nth function. It allows you to grab an element based on its index. That'd be better than tons of (next (next (next rows))) stuff. user= (doc nth) - clojure.core/nth ([coll index] [coll index not-found]) Returns the

Re: Re: Handling java streams..

2011-06-28 Thread Ken Wesson
On Tue, Jun 28, 2011 at 2:19 AM, Meikel Brandmeyer m...@kotka.de wrote: Hi, Am Montag, 27. Juni 2011 23:50:52 UTC+2 schrieb Ken Wesson: a) it isn't found by searching the docs in many of the usual ways; Is that really so hard? http://clojure.github.com/clojure top-right TOC:

Re: Re: Handling java streams..

2011-06-28 Thread Sean Corfield
On Tue, Jun 28, 2011 at 10:40 AM, Ken Wesson kwess...@gmail.com wrote: How else do you propose to explain the observation that if it isn't in clojure.core, it tends to be underused? :) Well, that's your observation so it's rather circular logic :) -- Sean A Corfield -- (904) 302-SEAN An

Re: Best Way To Extract Data From Lazy Sequence

2011-06-28 Thread octopusgrabbus
Thanks. That works perfectly. (ns test-csv (:gen-class) (:use clojure.contrib.command-line) (:use clojure-csv.core)) (defn x1 [val1 val2] (println val1 val2)) (defn process-file Process csv file and prints a column in every row [file-name] (let [data (slurp file-name)

How To Supply Multiple Values To Function In Map

2011-06-28 Thread octopusgrabbus
Given this sample: (ns test-csv (:gen-class) (:use clojure.contrib.command-line) (:use clojure-csv.core)) (defn x1 [val1 val2] (println val1 val2)) (defn process-file Process csv file and prints a column in every row [file-name] (let [data (slurp file-name) rows

Re: How To Supply Multiple Values To Function In Map

2011-06-28 Thread Mark Rathwell
map takes a function and a collection. So, that function can be: 1. named: - define the function on it own, using the defn macro - pass it as first argument to map (def coll [[1 2] [3 4] [4 5]]) (defn foo [x y] (println x y)) (map foo coll) 2. anonymous: - use

Re: How To Supply Multiple Values To Function In Map

2011-06-28 Thread octopusgrabbus
Thanks. I've followed most of what you've written except how the symbol col fits into this, unless you're using it as map values. On Jun 28, 3:11 pm, Mark Rathwell mark.rathw...@gmail.com wrote: map takes a function and a collection.  So, that function can be:  1. named:    - define the

Re: How To Supply Multiple Values To Function In Map

2011-06-28 Thread Mark Rathwell
coll is the vector defined at the top of each code listing in the examples given, and is used as the second argument to map in all examples. Sent from my iPhone On Jun 28, 2011, at 3:20 PM, octopusgrabbus octopusgrab...@gmail.com wrote: Thanks. I've followed most of what you've written

Re: ordered map in Clojure?

2011-06-28 Thread Tassilo Horn
Alan Malloy a...@malloys.org writes: Hi Alan, ArrayMap isn't very performant for large collections. You might like https://github.com/flatland/ordered in my clojure app, I totally rely on ordered sets. Currently, I use https://github.com/ninjudd/ordered-set for which I've implemented

Any ways to prevent protocol functions from being hardcoded in?

2011-06-28 Thread Brian Marick
I'm looking to do something like this: (defprotocol Addable (add-fields [this])) (defrecord MyRecord [a b] Addable (add-fields [this] (+ a b))) ;;; Magic happens here (defn indirect-adder [a b] (add-fields (MyRecord. a b))) (with-definition-of-add-fields-changed-to (fn [_] hi

dj updates

2011-06-28 Thread Brent Millare
It's been a year and I'm still using dj and still developing for it. git://github.com/bmillare/dj.git Some recent additions: * You can depend on clojure contrib github projects via: :src-dependencies [clojure/core.logic] All projects with clojure/ prefixed to the name are considered to be a

Re: Any ways to prevent protocol functions from being hardcoded in?

2011-06-28 Thread Stuart Sierra
The protocol method `add-fields` becomes an ordinary Clojure Var. You can temporarily change its root binding using `with-redefs` in 1.3. -S -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to

Re: Mocking framework

2011-06-28 Thread Brian Marick
On Jun 28, 2011, at 7:23 AM, László Török wrote: ...and a classic (not clojure specific) http://codebetter.com/gregyoung/2008/02/13/mocks-are-a-code-smell/ One thing I'm trying to emphasize with Midje is that mocking in the context of a functional language is (can be) about the logical

Re: Any ways to prevent protocol functions from being hardcoded in?

2011-06-28 Thread Brian Marick
On Jun 28, 2011, at 4:17 PM, Stuart Sierra wrote: The protocol method `add-fields` becomes an ordinary Clojure Var. You can temporarily change its root binding using `with-redefs` in 1.3. `with-redefs` has no effect on an already-compiled function that uses a defrecord-defined function. I

lexer written in clojure?

2011-06-28 Thread Paul Bernard
I've done a bit of reading on fnparse and found it be a cleanly implemented parser, suitable to my purposes. That said, it appears to still be dependent upon an external lexer for its feed, similar to most parsers. Aside from those lexers implemented directly in Java such as JLex is anyone

Translating Java code with nested for loops

2011-06-28 Thread Bhinderwala, Shoeb
Hi I have been learning clojure for some time but am a bit stumped when translating code with nested for loops. Can someone help me to translate the following java code to clojure elegantly: The inputs are two arrays of type double of the same length - dailyValues and totalValues. The output

ClassCastException on 'clojure.data.json/print-json'

2011-06-28 Thread Timothy Washington
I'm trying to do a simple print-json, and am getting a ClassCastException in the data.json library. I'm using [org.clojure/clojure 1.3.0-beta1] and [org.clojure/data.json 0.1.0]. So… * lein repl * *…* *user = (require 'clojure.data.json)* *nil * * * *user = (clojure.data.json/print-json

Idiomatic way to reference a bundled data file from Clojure source?

2011-06-28 Thread stu
Hi, I'd like to bundle a collection of (JSON) datafiles with a Clojure project source tree so that Clojure functions can reliably find and open those datafiles. What's the idiomatic way of going about this? In the past with other languages I've used tricks like Ruby's .dirname(__FILE__)/...

Re: ClassCastException on 'clojure.data.json/print-json'

2011-06-28 Thread Timothy Washington
Ok, so I fixed the problem by changing A) to B) A) (*defn *print-json ... (*write-json* x **out** escape-unicode))) to B) (*defn *print-json ... (*write-json* *(PrintWriter. *out*)* escape-unicode))) The only thing now, is that the 'nil' return value suffixes itself. I can

Re: Idiomatic way to reference a bundled data file from Clojure source?

2011-06-28 Thread Dave Ray
Hey, I don't have a good example, but the right way to do is with resources which are basically just files that live on the classpath: * Put the files in a folder on your classpath. If your using leiningen, the resources/ directory does this by default. * Get a URL to the file with

Re: Idiomatic way to reference a bundled data file from Clojure source?

2011-06-28 Thread Stephen C. Gilardi
I'd like to bundle a collection of (JSON) datafiles with a Clojure project source tree so that Clojure functions can reliably find and open those datafiles. What's the idiomatic way of going about this? One idiomatic way to do this in Clojure is: - store the files within a directory

Re: ClassCastException on 'clojure.data.json/print-json'

2011-06-28 Thread gaz jones
are you trying to turn something into a json string? if so, the json-str function is probably what you are looking for: user (json/json-str {:a b}) {\a\:\b\} by the way, the nil in your previous email is not being suffixed to the string, its simply the return of the function getting written to

Guide to Programming in Clojure for Beginners

2011-06-28 Thread Tim Robinson
I'm fairly new to Programming, Clojure and Blogging, but I did manage to write a few posts about Clojure in my spare time. http://blackstag.com/blog.posting?id=5 I have now have a newly found appreciation for how much effort this kind of stuff can be :) Feedback is always welcome. Regards, Tim

Re: Translating Java code with nested for loops

2011-06-28 Thread David Sletten
On Jun 28, 2011, at 8:20 PM, Bhinderwala, Shoeb wrote: The inputs are two arrays of type double of the same length – dailyValues and totalValues. The output is the array contrib of the same length. int n = dailyValues.length; for (int i = 0; i n; i++) {

Re: ClassCastException on 'clojure.data.json/print-json'

2011-06-28 Thread Timothy Washington
Hey Gareth, Yes, in my library, I'm returning a string. So indeed I will be using json-str. But on the command-line, I sometimes want to print or pretty-print something out. I forked data.json and submitted a pull request with the '(PrintWriter. *out*)' fix put in. Hopefully it solves the

Re: Idiomatic way to reference a bundled data file from Clojure source?

2011-06-28 Thread stu
On Jun 29, 12:17 pm, Stephen C. Gilardi squee...@mac.com wrote: I'd like to bundle a collection of (JSON) datafiles with a Clojure project source tree so that Clojure functions can reliably find and open those datafiles. What's the idiomatic way of going about this? Many thanks to

Re: Translating Java code with nested for loops

2011-06-28 Thread Justin Kramer
Here's one way. (defn tails [coll] (take-while seq (iterate rest coll))) (defn calc [total-values daily-values] (map * daily-values (for [tail (tails total-values)] (reduce #(* %1 (inc (/ %2 100.0))) 1.0

Re: ordered map in Clojure?

2011-06-28 Thread Alan Malloy
Well, I wrote the clojure version after boasting to ninjudd that deftype would let you do it without writing any java at all. I did some simple-minded benchmarking, and while I don't recall the exact numbers his java version is ~10-50% faster. If you look through the git logs, somewhere I have a

Hygenic approach for using Java2D from Clojure?

2011-06-28 Thread stu
Hi, I'd like to use Java2D objects in a Clojure application. I understand that these mutable objects will be operating in a Clojure environment where immutability is the order of the day, and this is likely to cause problems. Can someone point me to some good examples of, or techniques for

Re: Translating Java code with nested for loops

2011-06-28 Thread David Sletten
On Jun 28, 2011, at 11:37 PM, David Sletten wrote: On Jun 28, 2011, at 8:20 PM, Bhinderwala, Shoeb wrote: The inputs are two arrays of type double of the same length – dailyValues and totalValues. The output is the array contrib of the same length. int n = dailyValues.length;