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 the mind-reading documentation site is not ready, yet. Until then I 
recommend to read (and experiment with) one or two random functions from the 
reference every day. In that way you (not you, Ken. you in general the 
newbie) get an overview and get familiar with the docs.

Sincerely
Meikel

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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 tools being thrown together, but maybe not being used
by many? The one exception maybe is https://github.com/marick/Midje?

Thanks, Erik.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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 want to save the memory or the 
repeated typing.
3. Ken bundled all persons in the map by language.  This may be the right 
solution for you or not.  But if you do so, note that the inner maps reside 
in a vector (square brackets)

Maybe something like this:

;; a function returning a map representing a person
(defn make-person [nationality first last]
  {:first first :last last :nationality nationality})

;; the data on which you base the creation of persons
;; This repeats the keyword for each person
(def persons-data
  [[:english Jim Silvester]
   [:english Stephen Howards]
   [:chinese ChiuChiu]])

;; combine the fn and the data
(def persons
  (into [] (map #(apply make-person %) persons-data)))


;; A second way of storing your data uses (almost) the representation 
suggested by Ken:
(def persons-data-2
  {:english [[Jim Silvester]
 [Stephen Howards]]
   :chinese [ChiuChiu]})


;; This can be turned into a seq of persons like this
(def persons-2
  (map
   (fn [natio names]; can't use #() because it doesn't nest
 (map (fn [[first last]]; note the destructuring
(make-person natio first last))
  names))
   persons-data-2))


Hope this helps,
Stefan

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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 subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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 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 tools being thrown together, but maybe not being used
by many? The one exception maybe is https://github.com/marick/Midje?

Thanks, Erik.




--
-
Ola Ellnestam
Agical AB
Västerlånggatan 79, 2 tr
111 29 Stockholm, SWEDEN

Mobile: +46-708-754000
E-mail: ola.ellnes...@agical.se
Blog: http://ellnestam.wordpress.com
Twitter: ellnestam

--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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 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 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 tools being thrown together, but maybe not being used
 by many? The one exception maybe is https://github.com/marick/Midje?

 Thanks, Erik.



 --
 -
 Ola Ellnestam
 Agical AB
 Västerlånggatan 79, 2 tr
 111 29 Stockholm, SWEDEN

 Mobile: +46-708-754000
 E-mail: ola.ellnes...@agical.se
 Blog: http://ellnestam.wordpress.com
 Twitter: ellnestam

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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:

 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 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 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 tools being thrown together, but maybe not being used
  by many? The one exception maybe is https://github.com/marick/Midje?
 
  Thanks, Erik.
 
 
 
  --
  -
  Ola Ellnestam
  Agical AB
  Västerlånggatan 79, 2 tr
  111 29 Stockholm, SWEDEN
 
  Mobile: +46-708-754000
  E-mail: ola.ellnes...@agical.se
  Blog: http://ellnestam.wordpress.com
  Twitter: ellnestam
 
  --
  You received this message because you are subscribed to the Google
  Groups Clojure group.
  To post to this group, send email to clojure@googlegroups.com
  Note that posts from new members are moderated - please be patient with
 your
  first post.
  To unsubscribe from this group, send email to
  clojure+unsubscr...@googlegroups.com
  For more options, visit this group at
  http://groups.google.com/group/clojure?hl=en

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en




-- 
László Török

Skype: laczoka2000
Twitter: @laczoka

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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 (first %)) rows

(defn -main [ args]
  (with-command-line args
Get csv file name
[[file-name .csv file name 1]]
(println file-name:, file-name)
(if file-name
(process-file resultset.csv)
(process-file file-name

is it reasonable to write a recursive function that takes the lazy
sequence -- rows -- (returned from clojure-csv) and column numbers and
recurses until the appropriate column number is reached, or is it
better to build up a long series of expressions that would pull the
columns out?

For example, I believe I can pull out the second column by specifying
(first (next rows)), but it would look pretty awful to create a long
enough expression to get the 6th column in.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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 value at the index. get returns nil if index out of
  bounds, nth throws an exception unless not-found is supplied.  nth
  also works for strings, Java arrays, regex Matchers and Lists, and,
  in O(n) time, for sequences.

Alex

On Tue, Jun 28, 2011 at 7:42 AM, octopusgrabbus
octopusgrab...@gmail.com wrote:
 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 (first %)) rows

 (defn -main [ args]
  (with-command-line args
    Get csv file name
    [[file-name .csv file name 1]]
    (println file-name:, file-name)
    (if file-name
        (process-file resultset.csv)
        (process-file file-name

 is it reasonable to write a recursive function that takes the lazy
 sequence -- rows -- (returned from clojure-csv) and column numbers and
 recurses until the appropriate column number is reached, or is it
 better to build up a long series of expressions that would pull the
 columns out?

 For example, I believe I can pull out the second column by specifying
 (first (next rows)), but it would look pretty awful to create a long
 enough expression to get the 6th column in.

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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:
 clojure.java.io If I look for stream handling, wouldn't that sound
 interesting?

 Sadly the mind-reading documentation site is not ready, yet. Until then I
 recommend to read (and experiment with) one or two random functions from the
 reference every day. In that way you (not you, Ken. you in general the
 newbie) get an overview and get familiar with the docs.

Well, of course *I* know this. But I guess a lot of people mostly just
keep a browser tab parked at
http://clojure.github.com/clojure/clojure.core-api.html and
occasionally go to it and hit ctrl+F or F3 or whatever the usual
search hotkey is in Windoze apps, with results similar to using
find-doc except without cluttering their REPL history or backscroll or
getting scrolled out of view by using the REPL to try things.

How else do you propose to explain the observation that if it isn't
in clojure.core, it tends to be underused? :)

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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 Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/
Railo Technologies, Inc. -- http://www.getrailo.com/

Perfection is the enemy of the good.
-- Gustave Flaubert, French realist novelist (1821-1880)

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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)
rows (parse-csv data)]
(dorun (map #(println ( nth % 11 nil)) rows 

(defn -main [ args]
  (with-command-line args
Get csv file name
[[file-name .csv file name resultset.csv]]
[[file-name .csv file name 1]]
(println file-name:, file-name)
(process-file file-name)))

On Jun 28, 9:01 am, Alex Robbins alexander.j.robb...@gmail.com
wrote:
 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 value at the index. get returns nil if index out of
   bounds, nth throws an exception unless not-found is supplied.  nth
   also works for strings, Java arrays, regex Matchers and Lists, and,
   in O(n) time, for sequences.

 Alex

 On Tue, Jun 28, 2011 at 7:42 AM, octopusgrabbus







 octopusgrab...@gmail.com wrote:
  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 (first %)) rows

  (defn -main [ args]
   (with-command-line args
     Get csv file name
     [[file-name .csv file name 1]]
     (println file-name:, file-name)
     (if file-name
         (process-file resultset.csv)
         (process-file file-name

  is it reasonable to write a recursive function that takes the lazy
  sequence -- rows -- (returned from clojure-csv) and column numbers and
  recurses until the appropriate column number is reached, or is it
  better to build up a long series of expressions that would pull the
  columns out?

  For example, I believe I can pull out the second column by specifying
  (first (next rows)), but it would look pretty awful to create a long
  enough expression to get the 6th column in.

  --
  You received this message because you are subscribed to the Google
  Groups Clojure group.
  To post to this group, send email to clojure@googlegroups.com
  Note that posts from new members are moderated - please be patient with 
  your first post.
  To unsubscribe from this group, send email to
  clojure+unsubscr...@googlegroups.com
  For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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 (parse-csv data)]
(dorun (map #(println ( nth % 11 nil)) rows

(defn -main [ args]
  (with-command-line args
Get csv file name
[[file-name .csv file name resultset.csv]]
[[file-name .csv file name 1]]
(println file-name:, file-name)
(process-file file-name)))

I would like to print out two or more values, or creating a vector of
those values would be helpful. I have been experimenting, but either
get errors or nothing printed out.

I am just not sure how to approach this.
Thanks.
cmn

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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 shorthand notation #(...)
-- for one argument function, % represents the argument
-- for multiple args, use %1, %2, %3, etc., which represent arg in
specified position
  - use the fn special form (fn [x y] ...)
  - specify these inline in map call

   (def coll [[1 2] [3 4] [4 5]])

   (map #(println %1 %2) coll)

   (map (fn [x y] (println x y)) coll)



On Tue, Jun 28, 2011 at 2:58 PM, octopusgrabbus octopusgrab...@gmail.comwrote:

 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 (parse-csv data)]
(dorun (map #(println ( nth % 11 nil)) rows

 (defn -main [ args]
  (with-command-line args
Get csv file name
[[file-name .csv file name resultset.csv]]
[[file-name .csv file name 1]]
(println file-name:, file-name)
(process-file file-name)))

 I would like to print out two or more values, or creating a vector of
 those values would be helpful. I have been experimenting, but either
 get errors or nothing printed out.

 I am just not sure how to approach this.
 Thanks.
 cmn

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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 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 shorthand notation #(...)
     -- for one argument function, % represents the argument
     -- for multiple args, use %1, %2, %3, etc., which represent arg in
 specified position
   - use the fn special form (fn [x y] ...)
   - specify these inline in map call

    (def coll [[1 2] [3 4] [4 5]])

    (map #(println %1 %2) coll)

    (map (fn [x y] (println x y)) coll)

 On Tue, Jun 28, 2011 at 2:58 PM, octopusgrabbus 
 octopusgrab...@gmail.comwrote:







  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 (parse-csv data)]
         (dorun (map #(println ( nth % 11 nil)) rows

  (defn -main [ args]
   (with-command-line args
     Get csv file name
     [[file-name .csv file name resultset.csv]]
     [[file-name .csv file name 1]]
     (println file-name:, file-name)
     (process-file file-name)))

  I would like to print out two or more values, or creating a vector of
  those values would be helpful. I have been experimenting, but either
  get errors or nothing printed out.

  I am just not sure how to approach this.
  Thanks.
  cmn

  --
  You received this message because you are subscribed to the Google
  Groups Clojure group.
  To post to this group, send email to clojure@googlegroups.com
  Note that posts from new members are moderated - please be patient with
  your first post.
  To unsubscribe from this group, send email to
  clojure+unsubscr...@googlegroups.com
  For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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 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 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 shorthand notation #(...)
 -- for one argument function, % represents the argument
 -- for multiple args, use %1, %2, %3, etc., which represent arg in
 specified position
   - use the fn special form (fn [x y] ...)
   - specify these inline in map call
 
(def coll [[1 2] [3 4] [4 5]])
 
(map #(println %1 %2) coll)
 
(map (fn [x y] (println x y)) coll)
 
 On Tue, Jun 28, 2011 at 2:58 PM, octopusgrabbus 
 octopusgrab...@gmail.comwrote:
 
 
 
 
 
 
 
 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 (parse-csv data)]
(dorun (map #(println ( nth % 11 nil)) rows
 
 (defn -main [ args]
  (with-command-line args
Get csv file name
[[file-name .csv file name resultset.csv]]
[[file-name .csv file name 1]]
(println file-name:, file-name)
(process-file file-name)))
 
 I would like to print out two or more values, or creating a vector of
 those values would be helpful. I have been experimenting, but either
 get errors or nothing printed out.
 
 I am just not sure how to approach this.
 Thanks.
 cmn
 
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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 transient support which is already
incorporated and released.  Looking at your code, it basically looks
identical wrt features, except that your implementation is comletely in
clojure (and includes maps) while ninjudd's implementation is mainly
java.

If you know ninjudd's lib, can you give advice in what use-cases you'd
prefer your own lib?  Basically, in my scenario I only conjoin using
`into' but never disjoin, and performance for that is very important.
That's why I've implemented the transient support.  But as it turned
out, that didn't improve performance significantly, cause the
calculation of set members is far more expensive than aggregating
them...

Well, in any case, I think I'll simply try it out at the weekend.
Hopefully, I'm able to get some totally non-empirical benchmark results
from my test suite that I can poste here.

Bye,
Tassilo

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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 mom)
(indirect-adder 1 2)
= hi mom ; rather than 3

I expect there are no tricks like :dynamic true http://blog.n01se.net/?p=134 
that work, but I thought I'd check.

-
Brian Marick, Artisanal Labrador
Contract programming in Ruby and Clojure
Occasional consulting on Agile
www.exampler.com, www.twitter.com/marick

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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 contrib dependency.

* You can update projects, dj, and clojure, from within dj (a little
sugar is nice when deploying)

* You can run scripts in the context of a project with:

dj run filename [project-name]

Which is good for people that like swank or servers

Best,
Brent

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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 clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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 connections among functions 
in a system. That's why Midje avoids test terminology in favor of something 
that looks more logic/Prolog-ish. As a simple example: 

(fact ratings of movies with favorite actors are bumped a bit higher
 (rating ...movie...) = (roughly (* 1.2 4.0))
 (provided
 (critic-rating ...movie...) = 4.0
 (intersection (actors ...movie...) (favorite-actors)) =not= 
empty?)))

Mike Feathers and I will be having a presentation about tests as a means of 
abstraction at Agile2011 
http://program2011.agilealliance.org/event/873f7801c8b4f23fc1f0cfe0a45de2f5
and I've submitted a derivative session to Clojure Conj. 

[Besides sometimes allowing the removal of even more incidental complexity than 
straight clojure code does, another means of abstraction is deferring 
decisions about data structures. In the above, we don't have to know anything 
about what a movie is except that `critic-rating` and `actors` work with it, 
which is saying something like what `defprotocol` says.]

-
Brian Marick, Artisanal Labrador
Contract programming in Ruby and Clojure
Occasional consulting on Agile
www.exampler.com, www.twitter.com/marick

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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 would need something that says O compiler, being 
able to redef functions is actually more important to me right now than 
efficiency, so please emit code that notices redefs in, for example:

(defn indirect-adder [a b]
  (add-fields (MyRecord. a b)))

I have a kinda-kludgy workaround that does essentially that. It suffices.

-
Brian Marick, Artisanal Labrador
Contract programming in Ruby and Clojure
Occasional consulting on Agile
www.exampler.com, www.twitter.com/marick

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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 aware of a lexer 
implemented entirely in the Clojure language.  Ideally, a grammar based lexer 
generator would be of most interest but I would settle for a lexer DSL written 
in Clojure.  Ideas welcome.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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 is the array contrib of the same
length.

int n = dailyValues.length;

for (int i = 0; i  n; i++)
{
sum = 1.0;
for (int j = i + 1; j  n; j++)
{
sum *= (1.0 + (totalValues[j] / 100.0));
}

contrib[i] = sum * dailyValues[i];
}

Many thanks for your help.

-- Shoeb

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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 tim)*

*ClassCastException java.io.OutputStreamWriter cannot be cast to
java.io.PrintWriter  clojure.data.json/write-json-string (json.clj:229)*

*
*

*user= (clojure.data.json/print-json [1 2 3]) *

*ClassCastException java.io.OutputStreamWriter cannot be cast to
java.io.PrintWriter  clojure.data.json/write-json-array (json.clj:254)*

*
*

*user = (clojure.data.json/print-json { :a { :aa b } } ) *

*ClassCastException java.io.OutputStreamWriter cannot be cast to
java.io.PrintWriter  clojure.data.json/write-json-object (json.clj:238)*



Seems fairly straightforward (I've also tried on lists, nested hashes, etc).
If I look at the source for
json:229https://github.com/clojure/data.json/blob/master/src/main/clojure/clojure/data/json.clj
,
the 'out' variable looks to be a PrintWriter (and my local source version is
the same). And a stacktrace gives exactly that location


*user= (. *e printStackTrace)*

*java.lang.ClassCastException: java.io.OutputStreamWriter cannot be cast to
java.io.PrintWriter*

*at clojure.data.json$write_json_string.invoke(json.clj:229)*

*at
clojure.data.json$eval108$fn__109$G__99__118.invoke(json.clj:201)*

*at clojure.data.json$print_json.doInvoke(json.clj:331)*

*at clojure.lang.RestFn.invoke(RestFn.java:410)*

*at user$eval212.invoke(NO_SOURCE_FILE:24)*

*at clojure.lang.Compiler.eval(Compiler.java:6406)*

*at clojure.lang.Compiler.eval(Compiler.java:6372)*

*at clojure.core$eval.invoke(core.clj:2745)*

*at clojure.main$repl$read_eval_print__6016.invoke(main.clj:244)*

*at clojure.main$repl$fn__6021.invoke(main.clj:265)*

*at clojure.main$repl.doInvoke(main.clj:265)*

*at clojure.lang.RestFn.invoke(RestFn.java:512)*

*at user$eval7$acc__1060__auto8$fn__10.invoke(NO_SOURCE_FILE:1)*

*at clojure.lang.AFn.run(AFn.java:24)*

*at java.lang.Thread.run(Thread.java:636)*

*nil*

*user=*



Is there a problem in the data.json lib?


Tim

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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__)/...
construct but this kind of approach doesn't seem a good fit for
Clojure or for the JVM facilities it provides.

Can anyone point to a Clojure project that does this well?

Thanks,

Stu

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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
find out where that is. But I think this this could be fixed easily enough.
If you like, I can do this locally and, I guessing, submit a github pull
request.



user = (clojure.data.json/print-json tim)

timnil


user= (clojure.data.json/print-json [1 2 3])

[1,2,3]nil


user = (clojure.data.json/print-json { :a { :aa b } } )

{a:{aa:b}}nil



Tim




On Tue, Jun 28, 2011 at 8:59 PM, Timothy Washington twash...@gmail.comwrote:

 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 tim)*

 *ClassCastException java.io.OutputStreamWriter cannot be cast to
 java.io.PrintWriter  clojure.data.json/write-json-string (json.clj:229)*

 *
 *

 *user= (clojure.data.json/print-json [1 2 3]) *

 *ClassCastException java.io.OutputStreamWriter cannot be cast to
 java.io.PrintWriter  clojure.data.json/write-json-array (json.clj:254)*

 *
 *

 *user = (clojure.data.json/print-json { :a { :aa b } } ) *

 *ClassCastException java.io.OutputStreamWriter cannot be cast to
 java.io.PrintWriter  clojure.data.json/write-json-object (json.clj:238)*



 Seems fairly straightforward (I've also tried on lists, nested hashes,
 etc). If I look at the source for 
 json:229https://github.com/clojure/data.json/blob/master/src/main/clojure/clojure/data/json.clj
  ,
 the 'out' variable looks to be a PrintWriter (and my local source version is
 the same). And a stacktrace gives exactly that location


 *user= (. *e printStackTrace)*

 *java.lang.ClassCastException: java.io.OutputStreamWriter cannot be cast
 to java.io.PrintWriter*

 *at clojure.data.json$write_json_string.invoke(json.clj:229)*

 *at
 clojure.data.json$eval108$fn__109$G__99__118.invoke(json.clj:201)*

 *at clojure.data.json$print_json.doInvoke(json.clj:331)*

 *at clojure.lang.RestFn.invoke(RestFn.java:410)*

 *at user$eval212.invoke(NO_SOURCE_FILE:24)*

 *at clojure.lang.Compiler.eval(Compiler.java:6406)*

 *at clojure.lang.Compiler.eval(Compiler.java:6372)*

 *at clojure.core$eval.invoke(core.clj:2745)*

 *at clojure.main$repl$read_eval_print__6016.invoke(main.clj:244)*

 *at clojure.main$repl$fn__6021.invoke(main.clj:265)*

 *at clojure.main$repl.doInvoke(main.clj:265)*

 *at clojure.lang.RestFn.invoke(RestFn.java:512)*

 *at
 user$eval7$acc__1060__auto8$fn__10.invoke(NO_SOURCE_FILE:1)*

 *at clojure.lang.AFn.run(AFn.java:24)*

 *at java.lang.Thread.run(Thread.java:636)*

 *nil*

 *user=*



 Is there a problem in the data.json lib?


 Tim


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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 clojure.java.io/resource. If your file is
root/resources/my-project/my-resource.txt, you'd use (resource
my-project/my-resource.txt).
* Read the contents of the file by passing the resource URL to
clojure.java.io/reader or one of its friends.

When you jar up your app the resource files will be included in the
jar and just work.

Hope this helps.

Dave

On Tue, Jun 28, 2011 at 9:12 PM, stu stuart.hungerf...@gmail.com wrote:
 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__)/...
 construct but this kind of approach doesn't seem a good fit for
 Clojure or for the JVM facilities it provides.

 Can anyone point to a Clojure project that does this well?

 Thanks,

 Stu

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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 named resources at the top level of your 
project folder,
  - arrange for that folder to be in your classpath at runtime,
  - obtain a reference to the files at runtime using .getResource with a 
relative path.

If you use lieningen, the resources folder will be in your class path 
automatically and the files/directories it contains will be copied to the top 
level of your jar file if you make one.

Here's an example:

  (defn resource [path]
(when path
  (- (Thread/currentThread) .getContextClassLoader (.getResource path

  (require '[clojure.java.io :as io])
  (slurp (io/file (resource js/boo.js)))

I did this in a leiningen project called scratch. It returned the contents of 
the file

  scratch/resources/js/boo.js

because scratch/resources was on the classpath.

See also http://alexott.net/en/clojure/ClojureLein.html .

--Steve

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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
stdout by the repl immediately after the function has printed there
also. simply pressing enter at the repl will cause 'nil' to be printed
too...


On Tue, Jun 28, 2011 at 8:46 PM, Timothy Washington twash...@gmail.com wrote:
 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
 find out where that is. But I think this this could be fixed easily enough.
 If you like, I can do this locally and, I guessing, submit a github pull
 request.

 user = (clojure.data.json/print-json tim)

 timnil

 user= (clojure.data.json/print-json [1 2 3])

 [1,2,3]nil

 user = (clojure.data.json/print-json { :a { :aa b } } )

 {a:{aa:b}}nil

 Tim



 On Tue, Jun 28, 2011 at 8:59 PM, Timothy Washington twash...@gmail.com
 wrote:

 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 tim)

 ClassCastException java.io.OutputStreamWriter cannot be cast to
 java.io.PrintWriter  clojure.data.json/write-json-string (json.clj:229)

 user= (clojure.data.json/print-json [1 2 3])

 ClassCastException java.io.OutputStreamWriter cannot be cast to
 java.io.PrintWriter  clojure.data.json/write-json-array (json.clj:254)

 user = (clojure.data.json/print-json { :a { :aa b } } )

 ClassCastException java.io.OutputStreamWriter cannot be cast to
 java.io.PrintWriter  clojure.data.json/write-json-object (json.clj:238)

 Seems fairly straightforward (I've also tried on lists, nested hashes,
 etc). If I look at the source for json:229 , the 'out' variable looks to be
 a PrintWriter (and my local source version is the same). And a stacktrace
 gives exactly that location

 user= (. *e printStackTrace)

 java.lang.ClassCastException: java.io.OutputStreamWriter cannot be cast to
 java.io.PrintWriter

         at clojure.data.json$write_json_string.invoke(json.clj:229)

         at
 clojure.data.json$eval108$fn__109$G__99__118.invoke(json.clj:201)

         at clojure.data.json$print_json.doInvoke(json.clj:331)

         at clojure.lang.RestFn.invoke(RestFn.java:410)

         at user$eval212.invoke(NO_SOURCE_FILE:24)

         at clojure.lang.Compiler.eval(Compiler.java:6406)

         at clojure.lang.Compiler.eval(Compiler.java:6372)

         at clojure.core$eval.invoke(core.clj:2745)

         at clojure.main$repl$read_eval_print__6016.invoke(main.clj:244)

         at clojure.main$repl$fn__6021.invoke(main.clj:265)

         at clojure.main$repl.doInvoke(main.clj:265)

         at clojure.lang.RestFn.invoke(RestFn.java:512)

         at user$eval7$acc__1060__auto8$fn__10.invoke(NO_SOURCE_FILE:1)

         at clojure.lang.AFn.run(AFn.java:24)

         at java.lang.Thread.run(Thread.java:636)

 nil

 user=

 Is there a problem in the data.json lib?

 Tim

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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++)
 
 {
 
 sum = 1.0;
 
 for (int j = i + 1; j  n; j++)
 
 {
 
 sum *= (1.0 + (totalValues[j] / 100.0));
 
 }
 
 contrib[i] = sum * dailyValues[i];
 
 }
 

1. Are you sure that this does what you want it to?
2. What does it do?

There are two obvious red flags with the code:
-You have a variable called 'sum' which is really a product.
-You never use index 0 of totalValues

Have all good days,
David Sletten




-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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 problem.

And yes, the repl does spit out the result of the last command. I probably
misstated that as a problem (wanted something prettier at the moment). It's
not, as json.clj internally uses .print.


Thanks

Tim Washington
twash...@gmail.com
416.843.9060



On Tue, Jun 28, 2011 at 11:03 PM, gaz jones gareth.e.jo...@gmail.comwrote:

 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
 stdout by the repl immediately after the function has printed there
 also. simply pressing enter at the repl will cause 'nil' to be printed
 too...


 On Tue, Jun 28, 2011 at 8:46 PM, Timothy Washington twash...@gmail.com
 wrote:
  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
  find out where that is. But I think this this could be fixed easily
 enough.
  If you like, I can do this locally and, I guessing, submit a github pull
  request.
 
  user = (clojure.data.json/print-json tim)
 
  timnil
 
  user= (clojure.data.json/print-json [1 2 3])
 
  [1,2,3]nil
 
  user = (clojure.data.json/print-json { :a { :aa b } } )
 
  {a:{aa:b}}nil
 
  Tim
 
 
 
  On Tue, Jun 28, 2011 at 8:59 PM, Timothy Washington twash...@gmail.com
  wrote:
 
  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 tim)
 
  ClassCastException java.io.OutputStreamWriter cannot be cast to
  java.io.PrintWriter  clojure.data.json/write-json-string (json.clj:229)
 
  user= (clojure.data.json/print-json [1 2 3])
 
  ClassCastException java.io.OutputStreamWriter cannot be cast to
  java.io.PrintWriter  clojure.data.json/write-json-array (json.clj:254)
 
  user = (clojure.data.json/print-json { :a { :aa b } } )
 
  ClassCastException java.io.OutputStreamWriter cannot be cast to
  java.io.PrintWriter  clojure.data.json/write-json-object (json.clj:238)
 
  Seems fairly straightforward (I've also tried on lists, nested hashes,
  etc). If I look at the source for json:229 , the 'out' variable looks to
 be
  a PrintWriter (and my local source version is the same). And a
 stacktrace
  gives exactly that location
 
  user= (. *e printStackTrace)
 
  java.lang.ClassCastException: java.io.OutputStreamWriter cannot be cast
 to
  java.io.PrintWriter
 
  at clojure.data.json$write_json_string.invoke(json.clj:229)
 
  at
  clojure.data.json$eval108$fn__109$G__99__118.invoke(json.clj:201)
 
  at clojure.data.json$print_json.doInvoke(json.clj:331)
 
  at clojure.lang.RestFn.invoke(RestFn.java:410)
 
  at user$eval212.invoke(NO_SOURCE_FILE:24)
 
  at clojure.lang.Compiler.eval(Compiler.java:6406)
 
  at clojure.lang.Compiler.eval(Compiler.java:6372)
 
  at clojure.core$eval.invoke(core.clj:2745)
 
  at clojure.main$repl$read_eval_print__6016.invoke(main.clj:244)
 
  at clojure.main$repl$fn__6021.invoke(main.clj:265)
 
  at clojure.main$repl.doInvoke(main.clj:265)
 
  at clojure.lang.RestFn.invoke(RestFn.java:512)
 
  at
 user$eval7$acc__1060__auto8$fn__10.invoke(NO_SOURCE_FILE:1)
 
  at clojure.lang.AFn.run(AFn.java:24)
 
  at java.lang.Thread.run(Thread.java:636)
 
  nil
 
  user=
 
  Is there a problem in the data.json lib?
 
  Tim
 
  --
  You received this message because you are subscribed to the Google
  Groups Clojure group.
  To post to this group, send email to clojure@googlegroups.com
  Note that posts from new members are moderated - please be patient with
 your
  first post.
  To unsubscribe from this group, send email to
  clojure+unsubscr...@googlegroups.com
  For more options, visit this group at
  http://groups.google.com/group/clojure?hl=en

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group 

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 Dave and Stephen for your answers--just what I
needed.

Stu

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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
(rest tail)

In translating it, I first tried to visualize the algorithm[1]. Then I
transcribed that visualization into the usual suspects: map/for,
reduce, filter. Having a solid grasp of each of those -- not to
mention the rest of clojure.core -- is very helpful.

[1] http://i.imgur.com/XDZhm.png (crude drawing of the first step)

Hope that helps,

Justin

On Jun 28, 8:20 pm, Bhinderwala, Shoeb
sabhinderw...@wellington.com wrote:
 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 is the array contrib of the same
 length.

         int n = dailyValues.length;

         for (int i = 0; i  n; i++)
         {
             sum = 1.0;
             for (int j = i + 1; j  n; j++)
             {
                 sum *= (1.0 + (totalValues[j] / 100.0));
             }

             contrib[i] = sum * dailyValues[i];
         }

 Many thanks for your help.

 -- Shoeb

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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 version that is only 5% slower than his,
but when I added efficient disjoin support that slowed down the conj
case a bit; we decided that the purity was worth the performance cost.
If you want to resurrect that version, let me know and I'll hunt it
down.

I also have a version with even more-efficient disjoin but it slowed
conjing down to log2(n) instead of log32(n), and that performance hit,
while theoretically nil, was very noticeable in practice.

If I were using this for some performance-critical task and never
disjoined, I'd use ninjudd's version. Otherwise I'd use mine, just
because it's easier to build and tweak since it's in clojure.

On Jun 28, 12:54 pm, Tassilo Horn tass...@member.fsf.org wrote:
 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 transient support which is already
 incorporated and released.  Looking at your code, it basically looks
 identical wrt features, except that your implementation is comletely in
 clojure (and includes maps) while ninjudd's implementation is mainly
 java.

 If you know ninjudd's lib, can you give advice in what use-cases you'd
 prefer your own lib?  Basically, in my scenario I only conjoin using
 `into' but never disjoin, and performance for that is very important.
 That's why I've implemented the transient support.  But as it turned
 out, that didn't improve performance significantly, cause the
 calculation of set members is far more expensive than aggregating
 them...

 Well, in any case, I think I'll simply try it out at the weekend.
 Hopefully, I'm able to get some totally non-empirical benchmark results
 from my test suite that I can poste here.

 Bye,
 Tassilo

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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
safely using mutable Java objects in Clojure--especially with Clojure
parallel programming constructs in mind.

Thanks in advance,

Stu

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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;
 
 for (int i = 0; i  n; i++)
 
 {
 
 sum = 1.0;
 
 for (int j = i + 1; j  n; j++)
 
 {
 
 sum *= (1.0 + (totalValues[j] / 100.0));
 
 }
 
 contrib[i] = sum * dailyValues[i];
 
 }
 
 
 1. Are you sure that this does what you want it to?
 2. What does it do?
 
 There are two obvious red flags with the code:
 -You have a variable called 'sum' which is really a product.
 -You never use index 0 of totalValues
 

Assuming that your code is correct, the following reproduces your results:
(defn compute-contrib [daily-values total-values]
  (loop [contrib []
 daily-values daily-values
 total-values total-values]
(if (empty? daily-values)
  contrib
  (recur (conj contrib (* (first daily-values) (reduce (fn [sum 
total-value] (* sum (+ (/ total-value 100.0) 1.0)))
   1.0
   (rest 
total-values
 (rest daily-values)
 (rest total-values )

In the outer loop you are working with each element of dailyValues and 
consecutively smaller subsequences of totalValues. In the inner loop you repeat 
a calculation using each of the remaining elements of totalValues starting with 
a seed value of 1.0.

The Clojure implementation uses 'loop' to traverse each of the input sequences. 
On each iteration we use 'reduce' to do the work of the inner loop (notice that 
'reduce' is working with (rest total-values) rather than simply total-values 
itself, so we discard the first element each time just as your inner loop 
does), multiply that by the current element of interest in daily-values and 
then accumulate the result by conjoining it with our result 'contrib'.

The mental shift that you need to make involves forgetting about the index 
variables i and j and thinking instead about what the loops are accomplishing. 
If an inner loop is collapsing a sequence to a single result as above, then 
'reduce' is what you want to use. Other inner loops might require 'map' or 
'filter' depending on the computation.

Have all good days,
David Sletten




-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en