Re: Newbie question

2016-09-05 Thread Andy Fingerhut
On Mon, Sep 5, 2016 at 9:25 AM, hiskennyness  wrote:

>
> In other languages you might see:
>
> (defn himom [] ..)
> (defn himom [x] ...)
> (defn himom [x y z] ...)
>
>
> Come to think of it, maybe Clojure does that, too, (nooby myself) but the
> Clojure syntax for overloading I know puts each definition under the same
> defn, wrapping each in parens):
>
> (defn himom
>  ([] ..)
>  ([x] ...)
>  ([x y z] ...))
>
>
FYI, what actually happens in Clojure if you attempt the first kind of code
is that function himem will be defined once, then redefined twice, ending
by being a function that takes 3 arguments only.  If you want a function
that takes multiple different arities, you must use either the latter way
of defining it, or if you want 'n or more arguments', the syntax (defn
himom [required-arg1 required-arg2 & optional-args] ...)

Andy

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Newbie question

2016-09-05 Thread hiskennyness


On Sunday, September 4, 2016 at 4:58:34 PM UTC-4, Charlie wrote:
>
> I'm going through the Do Things: A Clojure Crash Course, and the following 
> example (in REPL) is presented:
>
> (defn recursive-printer
>   ([]
>  (recursive-printer 0))
>   ([iteration]
>  (println iteration)
>  (if (> iteration 3)
>(println "Goodbye!")
>(recursive-printer (inc iteration)(recursive-printer); => 
> Iteration 0; => Iteration 1; => Iteration 2; => Iteration 3; => Iteration 4; 
> => Goodbye!
>
>
> This works as expected, but I don't understand the syntax of the function 
> definition. Specifically: (defn recursive-printer ([] (recursive-printer 
> 0)). Isn't the parameter list supposed to be a vector [] not ([]...)? Also, 
> I don't see how [iteration] is resolved on the next line.
>
> Thanx for any help!
>
>
You may be familiar with function overloading in other languages, where one 
can define multiple functions with the same name as long as their 
signatures (parameter lists) are different. Clojure does not have types on 
its parameters, but can still support overloading as long as the arities 
(parameter counts) are different.

In other languages you might see:

(defn himom [] ..)
(defn himom [x] ...)
(defn himom [x y z] ...)


Come to think of it, maybe Clojure does that, too, (nooby myself) but the 
Clojure syntax for overloading I know puts each definition under the same 
defn, wrapping each in parens):

(defn himom
 ([] ..)
 ([x] ...)
 ([x y z] ...))

 hth,kt

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Newbie question

2016-09-04 Thread Charlie
Thanx Colin & James - got it now - Charlie

On Sunday, September 4, 2016 at 5:31:40 PM UTC-4, Colin Yates wrote:
>
> This form allows the fn to have multiple arities. So if I call 
> (recursive-printer) it will 'invoke' ([] (recursive-printer 0)). If I call 
> (recursive-printer 1) then it will 'invoke' ([iteration] ...).
>
> HTH
>
> -- 
>   Colin Yates
>   colin...@gmail.com 
>
>
>
> On Sun, 4 Sep 2016, at 09:54 PM, Charlie wrote:
>
> I'm going through the Do Things: A Clojure Crash Course, and the following 
> example (in REPL) is presented:
>
> (defn recursive-printer
>   ([]
>  (recursive-printer 0))
>   ([iteration]
>  (println iteration)
>  (if (> iteration 3)
>(println "Goodbye!")
>(recursive-printer (inc iteration)(recursive-printer); => 
> Iteration 0; => Iteration 1; => Iteration 2; => Iteration 3; => Iteration 4; 
> => Goodbye!
>
>
> This works as expected, but I don't understand the syntax of the function 
> definition. Specifically: (defn recursive-printer ([] (recursive-printer 
> 0)). Isn't the parameter list supposed to be a vector [] not ([]...)? Also, 
> I don't see how [iteration] is resolved on the next line.
>
> Thanx for any help!
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+u...@googlegroups.com .
> For more options, visit https://groups.google.com/d/optout.
>
>
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Newbie question

2016-09-04 Thread Colin Yates
This form allows the fn to have multiple arities. So if I call (recursive-
printer) it will 'invoke' ([] (recursive-printer 0)). If I call (recursive-
printer 1) then it will 'invoke' ([iteration] ...).

HTH

--
  Colin Yates
  colin.ya...@gmail.com



On Sun, 4 Sep 2016, at 09:54 PM, Charlie wrote:
> I'm going through the Do Things: A Clojure Crash Course, and the
> following example (in REPL) is presented:
>
> (defn recursive-printer  ([]  (recursive-printer ))  ([iteration]
> (println iteration)  (if (> iteration 3)  (println "Goodbye!")  (recursive-
> printer (inc iteration) (recursive-printer) ; => Iteration 0 ; =>
> Iteration 1 ; => Iteration 2 ; => Iteration 3 ; => Iteration 4 ; =>
> Goodbye!
>
> This works as expected, but I don't understand the syntax of the
> function definition. Specifically: (defn recursive-printer ([] (recursive-
> printer 0)). Isn't the parameter list supposed to be a vector []
> not ([]...)? Also, I don't see how [iteration] is resolved on the
> next line.
>
> Thanx for any help!
>
>
> --
>  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 unsubscribe from this group and stop receiving emails from it,
>  send an email to clojure+unsubscr...@googlegroups.com.
>  For more options, visit https://groups.google.com/d/optout.

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Newbie question

2016-09-04 Thread James Reeves
Functions in Clojure can behave differently depending on the number of
arguments they receive (their "arity"). A function can be written:

(defn foo [x]
  (str "foo" x))

But you can also write:

(defn foo
  ([] "empty foo")
  ([x] (str "foo" x))

This will do different things depending on the number of arguments:

(foo)
=> "empty foo"
(foo "bar")
=> "foobar"

- James

On 4 September 2016 at 21:54, Charlie  wrote:

> I'm going through the Do Things: A Clojure Crash Course, and the following
> example (in REPL) is presented:
>
> (defn recursive-printer
>   ([]
>  (recursive-printer 0))
>   ([iteration]
>  (println iteration)
>  (if (> iteration 3)
>(println "Goodbye!")
>(recursive-printer (inc iteration)(recursive-printer); => 
> Iteration 0; => Iteration 1; => Iteration 2; => Iteration 3; => Iteration 4; 
> => Goodbye!
>
>
> This works as expected, but I don't understand the syntax of the function
> definition. Specifically: (defn recursive-printer ([] (recursive-printer
> 0)). Isn't the parameter list supposed to be a vector [] not ([]...)? Also,
> I don't see how [iteration] is resolved on the next line.
>
> Thanx for any help!
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Newbie question

2016-09-04 Thread Charlie
I'm going through the Do Things: A Clojure Crash Course, and the following 
example (in REPL) is presented:

(defn recursive-printer
  ([]
 (recursive-printer 0))
  ([iteration]
 (println iteration)
 (if (> iteration 3)
   (println "Goodbye!")
   (recursive-printer (inc iteration)(recursive-printer); => Iteration 
0; => Iteration 1; => Iteration 2; => Iteration 3; => Iteration 4; => Goodbye!


This works as expected, but I don't understand the syntax of the function 
definition. Specifically: (defn recursive-printer ([] (recursive-printer 
0)). Isn't the parameter list supposed to be a vector [] not ([]...)? Also, 
I don't see how [iteration] is resolved on the next line.

Thanx for any help!

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Newbie Question: Why is "reduced?" used in the reductions function?

2015-10-17 Thread Alex Eberts
Ah, that makes total sense. 
Thanks for the assistance!
best,
Alex

On Saturday, October 17, 2015 at 7:35:00 AM UTC-4, Nicola Mometto wrote:
>
>
> The `reduced?` check is there in case somebody returns a `reduced` as 
> acc value from the reducing function, as a way to terminate the 
> reduction early: 
>
> user=> (reductions (fn [_ x] (if (= 10 x) (reduced x) x)) (range)) 
> (0 1 2 3 4 5 6 7 8 9 10) 
>
> deref is the way to retrieve the value of a reduced object: 
> user=> (deref (reduced 1)) 
> 1 
>
>
> Alex Eberts writes: 
>
> > Hi All, 
> > 
> > Could someone please explain why reduced? is being used in the 
> reductions 
> > function (below)? From what I understand reduced? checks if there has 
> been 
> > a call to reduced and I don't see where that might be happening. 
> > 
> > Also, why is the deref macro being used with init? 
> > 
> > thanks, 
> > Alex 
> > 
> > 
> > (defn reductions 
> >   "Returns a lazy seq of the intermediate values of the reduction (as 
> >   per reduce) of coll by f, starting with init." 
> >   {:added "1.2"} 
> >   ([f coll] 
> >  (lazy-seq 
> >   (if-let [s (seq coll)] 
> > (reductions f (first s) (rest s)) 
> > (list (f) 
> >   ([f init coll] 
> >  (if (reduced? init) 
> >(list @init) 
> >(cons init 
> >  (lazy-seq 
> >   (when-let [s (seq coll)] 
> > (reductions f (f init (first s)) (rest s 
> > 
> > from: 
> > 
> https://github.com/clojure/clojure/blob/clojure-1.7.0/src/clj/clojure/core.clj#L6921
>  
>
> -- 
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Newbie Question: Why is "reduced?" used in the reductions function?

2015-10-17 Thread Nicola Mometto

The `reduced?` check is there in case somebody returns a `reduced` as
acc value from the reducing function, as a way to terminate the
reduction early:

user=> (reductions (fn [_ x] (if (= 10 x) (reduced x) x)) (range))
(0 1 2 3 4 5 6 7 8 9 10)

deref is the way to retrieve the value of a reduced object:
user=> (deref (reduced 1))
1


Alex Eberts writes:

> Hi All,
>
> Could someone please explain why reduced? is being used in the reductions
> function (below)? From what I understand reduced? checks if there has been
> a call to reduced and I don't see where that might be happening.
>
> Also, why is the deref macro being used with init?
>
> thanks,
> Alex
>
>
> (defn reductions
>   "Returns a lazy seq of the intermediate values of the reduction (as
>   per reduce) of coll by f, starting with init."
>   {:added "1.2"}
>   ([f coll]
>  (lazy-seq
>   (if-let [s (seq coll)]
> (reductions f (first s) (rest s))
> (list (f)
>   ([f init coll]
>  (if (reduced? init)
>(list @init)
>(cons init
>  (lazy-seq
>   (when-let [s (seq coll)]
> (reductions f (f init (first s)) (rest s
>
> from:
> https://github.com/clojure/clojure/blob/clojure-1.7.0/src/clj/clojure/core.clj#L6921

--

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Newbie Question: Why is "reduced?" used in the reductions function?

2015-10-17 Thread Alex Eberts
Hi All,

Could someone please explain why reduced? is being used in the reductions 
function (below)? From what I understand reduced? checks if there has been 
a call to reduced and I don't see where that might be happening.

Also, why is the deref macro being used with init?

thanks,
Alex


(defn reductions
  "Returns a lazy seq of the intermediate values of the reduction (as
  per reduce) of coll by f, starting with init."
  {:added "1.2"}
  ([f coll]
 (lazy-seq
  (if-let [s (seq coll)]
(reductions f (first s) (rest s))
(list (f)
  ([f init coll]
 (if (reduced? init)
   (list @init)
   (cons init
 (lazy-seq
  (when-let [s (seq coll)]
(reductions f (f init (first s)) (rest s

from: 
https://github.com/clojure/clojure/blob/clojure-1.7.0/src/clj/clojure/core.clj#L6921

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: newbie question: how to selectively iterate through a tree of directories ?

2015-10-03 Thread Gary Verhaegen
I'm on Windows at the moment, so I can't test, but I think you can
filter on isFile:

(for [file (file-seq dir)
  :where (.isFile file)]
  (.getName file))

should work, I think.

On 3 October 2015 at 07:36,   wrote:
> Under linux, I have a tree of directories like this:
>
> /path/top
>
> /path/top/dir1  (in here there are two files f1, f2)
>
> /path/top/dir2 -> /another-path/dir2 (a symbolic link)
>
>  and under /another-path/dir2 there are two files g1, g2
>
> If I use below code, I would get a list of files f1, f2, and g1, g2
>
> (def directory (clojure.java.io/file "/path/top"))
> (def files
> (for [file (file-seq directory)] (.getName file)))
> (files)
>
> BUT I want to skip traversing the directory dir2 since it is a symbolic
> link.
>
> i.e. the list of files that I want to get is f1, f2 only.
>
> Could you please suggest a way to do this ?
>
> THanks
>
> HP
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


newbie question: how to selectively iterate through a tree of directories ?

2015-10-03 Thread hpwei01


Under linux, I have a tree of directories like this:

/path/top

/path/top/dir1  (in here there are two files f1, f2)

/path/top/dir2 -> /another-path/dir2 (a symbolic link) 

 and under /another-path/dir2 there are two files g1, g2

If I use below code, I would get a list of files f1, f2, and g1, g2

(def directory (clojure.java.io/file "/path/top"))(def files 
(for [file (file-seq directory)] (.getName file)))(files)

BUT I want to skip traversing the directory dir2 since it is a symbolic link.

i.e. the list of files that I want to get is f1, f2 only.

Could you please suggest a way to do this ?

THanks

HP

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: newbie question on agent/transaction

2015-07-15 Thread William la Forge
Or perhaps find a way to extend agents. hm?

On Wednesday, July 15, 2015 at 9:45:29 AM UTC-4, William la Forge wrote:
>
> Thanks, Ragnar.
>
> My reason for asking is that I've implemented a robust form of actor in 
> Java https://github.com/laforge49/JActor2 and want to play with a 
> simplified version in Clojure as a first project in the language. But I'm 
> just hardly getting started. I've only been looking at Clojure for a week 
> and last touched lisp in 1970. And I have not even looked at the code 
> implementing agents yet.
>
> So it looks like it would be best to ignore transactions in an initial 
> draft. 
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: newbie question on agent/transaction

2015-07-15 Thread William la Forge
Thanks, Ragnar.

My reason for asking is that I've implemented a robust form of actor in 
Java https://github.com/laforge49/JActor2 and want to play with a 
simplified version in Clojure as a first project in the language. But I'm 
just hardly getting started. I've only been looking at Clojure for a week 
and last touched lisp in 1970. And I have not even looked at the code 
implementing agents yet.

So it looks like it would be best to ignore transactions in an initial 
draft. 

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: newbie question on agent/transaction

2015-07-15 Thread Ragnar Dahlén
You can check with `(clojure.lang.LockingTransaction/isRunning)` (the io! 
macro does this) but I'm not sure if it's considered a public API.

https://github.com/clojure/clojure/blob/f6a90ff2931cec35cca0ca7cf7afe90ab99e3161/src/clj/clojure/core.clj#L2390

On Wednesday, 15 July 2015 13:53:11 UTC+1, Ragnar Dahlén wrote:
>
> Hi Bill,
>
> You are correct in that this involves close integration with the STM. The 
> agent implementation is aware of transactions and if a transaction is 
> running when dispatching an action, it will be enqneued in a special agent 
> action queue that STM implementation respects.
>
> AFAIK there is no public API for checking if a transaction is currently 
> running.
>
> See:
>
> https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Agent.java#L249
>
> https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LockingTransaction.java#L106
>
>
>
>
>
>
> On Wednesday, 15 July 2015 13:26:11 UTC+1, William la Forge wrote:
>>
>> On this page http://clojure.org/agents I read the following:
>>  "Agents are integrated with the STM - any dispatches made in a 
>> transaction are held until it commits, and are discarded if it is retried 
>> or aborted."
>>
>> So there must be a way to tell if a dispatch is made from within a 
>> transaction. Yet I am looking here http://clojure.org/refs and can not 
>> find any such function.
>>
>> What then is the means of determining if you are processing a 
>> transaction, or is this something that involves close integration with STM?
>>
>> thanks! --Bill
>>
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: newbie question on agent/transaction

2015-07-15 Thread Ragnar Dahlén
Hi Bill,

You are correct in that this involves close integration with the STM. The 
agent implementation is aware of transactions and if a transaction is 
running when dispatching an action, it will be enqneued in a special agent 
action queue that STM implementation respects.

AFAIK there is no public API for checking if a transaction is currently 
running.

See:
https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Agent.java#L249
https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LockingTransaction.java#L106






On Wednesday, 15 July 2015 13:26:11 UTC+1, William la Forge wrote:
>
> On this page http://clojure.org/agents I read the following:
>  "Agents are integrated with the STM - any dispatches made in a 
> transaction are held until it commits, and are discarded if it is retried 
> or aborted."
>
> So there must be a way to tell if a dispatch is made from within a 
> transaction. Yet I am looking here http://clojure.org/refs and can not 
> find any such function.
>
> What then is the means of determining if you are processing a transaction, 
> or is this something that involves close integration with STM?
>
> thanks! --Bill
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


newbie question on agent/transaction

2015-07-15 Thread William la Forge
On this page http://clojure.org/agents I read the following:
 "Agents are integrated with the STM - any dispatches made in a 
transaction are held until it commits, and are discarded if it is retried 
or aborted."

So there must be a way to tell if a dispatch is made from within a 
transaction. Yet I am looking here http://clojure.org/refs and can not find 
any such function.

What then is the means of determining if you are processing a transaction, 
or is this something that involves close integration with STM?

thanks! --Bill

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Newbie question about filtrering defrecord

2015-04-04 Thread Paul L. Snyder
On Sun, 05 Apr 2015, Michael Blume wrote:

> your list doesn't contain the records, your list contains the symbols 'a1
> and 'a2. You can't make a list the way you're trying to.

To be specific, you're quoting the list in your def, so the a1 and a2 symbols 
are
not evaluated.

  user=> (defrecord Ape [fname lname])
  user.Ape
  user=> (def a1 (->Ape "test1" "test2"))
  #'user/a1
  user=> (def a2 (->Ape "test3" "test4"))
  #'user/a2

  user=> '(a1 a2)
  (a1 a2)
  user=> (quote (a1 a2))
  (a1 a2)
  user=> (list a1 a2)
  (#user.Ape{:fname "test1", :lname "test2"} #user.Ape{:fname "test3", :lname 
"test4"})

  user=> (def alist (list a1 a2))
  #'user/alist
  user=> (filter #(= "test1" (:fname %)) alist)
  (#user.Ape{:fname "test1", :lname "test2"})

  ;; Clojure idioms tend toward vectors and vector literals rather than
  ;; lists. If you have a background in Common Lisp or Scheme, this can
  ;; take some getting used to. One nice consequence is you don't have
  ;; to worry about quoting most of the time.
  user=> (filter #(= "test1" (:fname %)) [a1 a2])
  (#user.Ape{:fname "test1", :lname "test2"})

Cheers,
Paul

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Newbie question about filtrering defrecord

2015-04-04 Thread Michael Blume
your list doesn't contain the records, your list contains the symbols 'a1
and 'a2. You can't make a list the way you're trying to.

On Sat, Apr 4, 2015 at 5:14 PM Luc Préfontaine 
wrote:

> You mean the a1 record no ?
>
>
> > Hi!
> >
> > I'm new to clojure, and have problem understanding how to filter a list
> of
> > defrecords.
> > I have tried different variations on the following:
> >
> > (defrecord Ape [fname lname])
> > (def a1 (->Ape "test1" "test2"))
> > (def a2 (->Ape "test3" "test4"))
> > (def alist '(a1 a2))
> >
> > (filter #(= "test1" (:fname %)) alist)
> >
> > I expect the filter to match the a2 record, but I obviously do something
> > wrong and would appreciate any suggestion.
> >
> > Kind regards
> > Magnus Jäverberg
> >
> > --
> > 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 unsubscribe from this group and stop receiving emails from it, send
> an email to clojure+unsubscr...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
> >
> --
> Luc Préfontaine sent by ibisMail!
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Newbie question about filtrering defrecord

2015-04-04 Thread Luc Préfontaine
You mean the a1 record no ?


> Hi!
> 
> I'm new to clojure, and have problem understanding how to filter a list of 
> defrecords. 
> I have tried different variations on the following:
> 
> (defrecord Ape [fname lname])
> (def a1 (->Ape "test1" "test2"))
> (def a2 (->Ape "test3" "test4"))
> (def alist '(a1 a2))
> 
> (filter #(= "test1" (:fname %)) alist)
> 
> I expect the filter to match the a2 record, but I obviously do something 
> wrong and would appreciate any suggestion.
> 
> Kind regards
> Magnus Jäverberg
> 
> -- 
> 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 unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
> 
--
Luc Préfontaine sent by ibisMail!

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Newbie question about filtrering defrecord

2015-04-04 Thread Magnus Javerberg
Hi!

I'm new to clojure, and have problem understanding how to filter a list of 
defrecords. 
I have tried different variations on the following:

(defrecord Ape [fname lname])
(def a1 (->Ape "test1" "test2"))
(def a2 (->Ape "test3" "test4"))
(def alist '(a1 a2))

(filter #(= "test1" (:fname %)) alist)

I expect the filter to match the a2 record, but I obviously do something 
wrong and would appreciate any suggestion.

Kind regards
Magnus Jäverberg

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: A newbie question with using parkour

2015-02-22 Thread Sunil S Nandihalli
Thanks Jeremy for the response. I was using clojure-1.7.0-alpha5 , parkour
6.2that looked was the original problem. After I changed the version to
clojure-1.6.0 I got past that problem and hit a new set of problems.
Marshall suggested that the issue could be because of mismatched
hadoop-versions. I am currently looking at those.
Thanks,
Sunil.

On Sun, Feb 22, 2015 at 11:50 PM, Jeremy Heiler 
wrote:

> What version of parkour are you using? That will help us match line
> numbers in the stracktrace with the code.
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: A newbie question with using parkour

2015-02-22 Thread Jeremy Heiler
What version of parkour are you using? That will help us match line 
numbers in the stracktrace with the code.


--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


A newbie question with using parkour

2015-02-22 Thread Sunil S Nandihalli
Hi Everybody,
 I am complete newbie to using parkour. I am having trouble just reading in
data. Can somebody help me figure out the problem.

The code I am using is here..

https://gist.github.com/52f4298e5b6ca6a46699

I agree that there is no other stage apart from the input. I had all other
stages but removed them to zero-in on the problem to create the smallest
possible code to reproduce the problem.
I am running the uber-jar with the following command

hadoop jar mr.jar

It is able to list the files which have been specified with a wild-card so
it seems like it is able to talk to the hdfs.
I am a complete noob to parkour .. so please excuse any stupid mistakes and
explain the same.

Thanks,
Sunil.

The error I get is here
#
15/02/22 12:22:26 ERROR parkour.tool: Uncaught exception:
java.lang.IllegalArgumentException: Don't know how to create ISeq from:
clojure.core.reducers$folder$reify__5580
java.lang.IllegalArgumentException: Don't know how to create ISeq from:
clojure.core.reducers$folder$reify__5580
at clojure.lang.RT.seqFrom(RT.java:506)
at clojure.lang.RT.seq(RT.java:487)
at clojure.core$seq__7216.invoke(core.clj:135)
at clojure.core.protocols$seq_reduce.invoke(protocols.clj:30)
at
clojure.core.protocols$eval10183$fn__10184.invoke(protocols.clj:42)
at
clojure.core.protocols$eval10104$fn__10105$G__10095__10118.invoke(protocols.clj:13)
at clojure.core$reduce.invoke(core.clj:6514)
at clojure.core$into.invoke(core.clj:6595)
at parkour.graph$execute.invoke(graph.clj:458)
at impressions.core$counter_tool.invoke(core.clj:14)
at impressions.core$tool.invoke(core.clj:21)
at clojure.lang.AFn.applyToHelper(AFn.java:156)
at clojure.lang.AFn.applyTo(AFn.java:144)
at clojure.core$apply.invoke(core.clj:628)
at parkour.tool.ParkourTool$fn__13080.invoke(tool.clj:33)
at parkour.tool$integral_STAR_.invoke(tool.clj:12)
at parkour.tool.ParkourTool.run(tool.clj:31)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70)
at parkour.tool$run.invoke(tool.clj:50)
at parkour.tool$run.invoke(tool.clj:45)
at impressions.core$_main.doInvoke(core.clj:25)
at clojure.lang.RestFn.invoke(RestFn.java:397)
at clojure.lang.AFn.applyToHelper(AFn.java:152)
at clojure.lang.RestFn.applyTo(RestFn.java:132)
at impressions.core.main(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.hadoop.util.RunJar.main(RunJar.java:212)

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: pigpen newbie question

2014-09-15 Thread Sunil S Nandihalli
Thanks Matt for the response. Like you said, I don't really need to be
using 1.7.0 I am doing quiet ok with 1.6.0
Thanks,
Sunil.

On Tue, Sep 16, 2014 at 9:28 AM, 'Matt Bossenbroek' via Clojure <
clojure@googlegroups.com> wrote:

> Sunil,
>
> I tried upgrading PigPen to Instaparse 1.3.4, but that pulled in Clojure
> 1.6.0 & now I'm running into some build/jar/versioning issues. I don't
> think I'll be able to get the update out as soon as promised, but it sounds
> like not using 1.7.0 will work for you in the meantime.
>
> -Matt
>
> On Thursday, September 11, 2014 at 7:52 PM, Sunil S Nandihalli wrote:
>
> Thanks Mark and Matt, changing the version back to clojure version 1.6.0
> fixed it.
> Sunil
>
> On Fri, Sep 12, 2014 at 7:05 AM, 'Matt Bossenbroek' via Clojure <
> clojure@googlegroups.com> wrote:
>
>  Just saw this response - disregard the questions I asked you on the
> pigpen support DL.
>
> I'll pull in the new instaparse & get a new PigPen build out soonish
> (within a day or two).
>
> -Matt
>
> On Thursday, September 11, 2014 at 6:28 PM, Mark Engelberg wrote:
>
> You're probably using Clojure 1.7.0 alpha 2, which introduced a new
> function called "cat" into the core namespace, which overlaps with a
> function in instaparse.
>
> A couple nights ago, I updated instaparse to version 1.3.4, with an update
> to deal with this change in alpha 2, but pigpen has not yet been updated to
> use that version of instaparse.
>
> You can either go back to a non-alpha release of Clojure, or wait for the
> pigpen folks to update, or perhaps there is some leiningen-fu you can do in
> the project.clj file to override the instaparse dependency loaded by pigpen
> with instaparse 1.3.4.
>
> On Thu, Sep 11, 2014 at 5:16 PM, Sunil S Nandihalli <
> sunil.nandiha...@gmail.com> wrote:
>
> Hi ,
>  I am trying to compile a simple clj file which does nothing apart from
> requiring the pigpen name-space and it fails to compile with the following
> error. Can anybody help?
>
> Attempting to call unbound fn: #'instaparse.combinators-source/cat
>
> the full stack trace is here.
> https://gist.github.com/sunilnandihalli/b400e21552ca97038e56
>
> Thanks,
> Sunil.
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
>  --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
>  --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
>  --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.

Re: pigpen newbie question

2014-09-15 Thread 'Matt Bossenbroek' via Clojure
Sunil,

I tried upgrading PigPen to Instaparse 1.3.4, but that pulled in Clojure 1.6.0 
& now I'm running into some build/jar/versioning issues. I don't think I'll be 
able to get the update out as soon as promised, but it sounds like not using 
1.7.0 will work for you in the meantime. 

-Matt


On Thursday, September 11, 2014 at 7:52 PM, Sunil S Nandihalli wrote:

> Thanks Mark and Matt, changing the version back to clojure version 1.6.0 
> fixed it.
> Sunil
> 
> 
> On Fri, Sep 12, 2014 at 7:05 AM, 'Matt Bossenbroek' via Clojure 
> mailto:clojure@googlegroups.com)> wrote:
> > Just saw this response - disregard the questions I asked you on the pigpen 
> > support DL. 
> > 
> > I'll pull in the new instaparse & get a new PigPen build out soonish 
> > (within a day or two). 
> > 
> > -Matt
> > 
> > 
> > On Thursday, September 11, 2014 at 6:28 PM, Mark Engelberg wrote:
> > 
> > > You're probably using Clojure 1.7.0 alpha 2, which introduced a new 
> > > function called "cat" into the core namespace, which overlaps with a 
> > > function in instaparse.
> > > 
> > > A couple nights ago, I updated instaparse to version 1.3.4, with an 
> > > update to deal with this change in alpha 2, but pigpen has not yet been 
> > > updated to use that version of instaparse.
> > > 
> > > You can either go back to a non-alpha release of Clojure, or wait for the 
> > > pigpen folks to update, or perhaps there is some leiningen-fu you can do 
> > > in the project.clj file to override the instaparse dependency loaded by 
> > > pigpen with instaparse 1.3.4.
> > > 
> > > On Thu, Sep 11, 2014 at 5:16 PM, Sunil S Nandihalli 
> > > mailto:sunil.nandiha...@gmail.com)> wrote:
> > > > Hi ,
> > > >  I am trying to compile a simple clj file which does nothing apart from 
> > > > requiring the pigpen name-space and it fails to compile with the 
> > > > following error. Can anybody help?
> > > > 
> > > > Attempting to call unbound fn: #'instaparse.combinators-source/cat
> > > > 
> > > > the full stack trace is here. 
> > > > https://gist.github.com/sunilnandihalli/b400e21552ca97038e56
> > > > 
> > > > Thanks,
> > > > Sunil.
> > > > 
> > > > 
> > > > -- 
> > > > 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 
> > > > (mailto: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 
> > > > (mailto:clojure%2bunsubscr...@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 unsubscribe from this group and stop receiving emails from it, send 
> > > > an email to clojure+unsubscr...@googlegroups.com 
> > > > (mailto:clojure+unsubscr...@googlegroups.com).
> > > > For more options, visit https://groups.google.com/d/optout.
> > > 
> > > -- 
> > > 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 
> > > (mailto: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 
> > > (mailto: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 unsubscribe from this group and stop receiving emails from it, send an 
> > > email to clojure+unsubscr...@googlegroups.com 
> > > (mailto:clojure+unsubscr...@googlegroups.com).
> > > For more options, visit https://groups.google.com/d/optout.
> > 
> > -- 
> > 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 
> > (mailto: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 
> > (mailto:clojure%2bunsubscr...@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 unsubscribe from this group and stop receiving emails from it, send an 
> > email to clojure+unsubscr...@googlegroups.com 
> > (mailto:clojure+unsubscr...@googlegroups.com).
> > For more options, visit https://groups.google.com/d/optout.
> 
> -- 
> You received this messag

Re: pigpen newbie question

2014-09-11 Thread Sunil S Nandihalli
Thanks Mark and Matt, changing the version back to clojure version 1.6.0
fixed it.
Sunil

On Fri, Sep 12, 2014 at 7:05 AM, 'Matt Bossenbroek' via Clojure <
clojure@googlegroups.com> wrote:

>  Just saw this response - disregard the questions I asked you on the
> pigpen support DL.
>
> I'll pull in the new instaparse & get a new PigPen build out soonish
> (within a day or two).
>
> -Matt
>
> On Thursday, September 11, 2014 at 6:28 PM, Mark Engelberg wrote:
>
> You're probably using Clojure 1.7.0 alpha 2, which introduced a new
> function called "cat" into the core namespace, which overlaps with a
> function in instaparse.
>
> A couple nights ago, I updated instaparse to version 1.3.4, with an update
> to deal with this change in alpha 2, but pigpen has not yet been updated to
> use that version of instaparse.
>
> You can either go back to a non-alpha release of Clojure, or wait for the
> pigpen folks to update, or perhaps there is some leiningen-fu you can do in
> the project.clj file to override the instaparse dependency loaded by pigpen
> with instaparse 1.3.4.
>
> On Thu, Sep 11, 2014 at 5:16 PM, Sunil S Nandihalli <
> sunil.nandiha...@gmail.com> wrote:
>
> Hi ,
>  I am trying to compile a simple clj file which does nothing apart from
> requiring the pigpen name-space and it fails to compile with the following
> error. Can anybody help?
>
> Attempting to call unbound fn: #'instaparse.combinators-source/cat
>
> the full stack trace is here.
> https://gist.github.com/sunilnandihalli/b400e21552ca97038e56
>
> Thanks,
> Sunil.
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
>  --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
>  --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: pigpen newbie question

2014-09-11 Thread Sunil S Nandihalli
Thanks Mark for the response. That was very quick. Let me see if moving to
clojure 1.6.0 fixes the issues.
Sunil.

On Fri, Sep 12, 2014 at 6:58 AM, Mark Engelberg 
wrote:

> You're probably using Clojure 1.7.0 alpha 2, which introduced a new
> function called "cat" into the core namespace, which overlaps with a
> function in instaparse.
>
> A couple nights ago, I updated instaparse to version 1.3.4, with an update
> to deal with this change in alpha 2, but pigpen has not yet been updated to
> use that version of instaparse.
>
> You can either go back to a non-alpha release of Clojure, or wait for the
> pigpen folks to update, or perhaps there is some leiningen-fu you can do in
> the project.clj file to override the instaparse dependency loaded by pigpen
> with instaparse 1.3.4.
>
> On Thu, Sep 11, 2014 at 5:16 PM, Sunil S Nandihalli <
> sunil.nandiha...@gmail.com> wrote:
>
>> Hi ,
>>  I am trying to compile a simple clj file which does nothing apart from
>> requiring the pigpen name-space and it fails to compile with the following
>> error. Can anybody help?
>>
>> Attempting to call unbound fn: #'instaparse.combinators-source/cat
>>
>> the full stack trace is here.
>> https://gist.github.com/sunilnandihalli/b400e21552ca97038e56
>>
>> Thanks,
>> Sunil.
>>
>> --
>> 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 unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: pigpen newbie question

2014-09-11 Thread 'Matt Bossenbroek' via Clojure
Just saw this response - disregard the questions I asked you on the pigpen 
support DL. 

I'll pull in the new instaparse & get a new PigPen build out soonish (within a 
day or two). 

-Matt


On Thursday, September 11, 2014 at 6:28 PM, Mark Engelberg wrote:

> You're probably using Clojure 1.7.0 alpha 2, which introduced a new function 
> called "cat" into the core namespace, which overlaps with a function in 
> instaparse.
> 
> A couple nights ago, I updated instaparse to version 1.3.4, with an update to 
> deal with this change in alpha 2, but pigpen has not yet been updated to use 
> that version of instaparse.
> 
> You can either go back to a non-alpha release of Clojure, or wait for the 
> pigpen folks to update, or perhaps there is some leiningen-fu you can do in 
> the project.clj file to override the instaparse dependency loaded by pigpen 
> with instaparse 1.3.4.
> 
> On Thu, Sep 11, 2014 at 5:16 PM, Sunil S Nandihalli 
> mailto:sunil.nandiha...@gmail.com)> wrote:
> > Hi ,
> >  I am trying to compile a simple clj file which does nothing apart from 
> > requiring the pigpen name-space and it fails to compile with the following 
> > error. Can anybody help?
> > 
> > Attempting to call unbound fn: #'instaparse.combinators-source/cat
> > 
> > the full stack trace is here. 
> > https://gist.github.com/sunilnandihalli/b400e21552ca97038e56
> > 
> > Thanks,
> > Sunil.
> > 
> > 
> > -- 
> > 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 
> > (mailto: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 
> > (mailto:clojure%2bunsubscr...@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 unsubscribe from this group and stop receiving emails from it, send an 
> > email to clojure+unsubscr...@googlegroups.com 
> > (mailto:clojure+unsubscr...@googlegroups.com).
> > For more options, visit https://groups.google.com/d/optout.
> 
> -- 
> 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 
> (mailto: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 
> (mailto: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 unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+unsubscr...@googlegroups.com 
> (mailto:clojure+unsubscr...@googlegroups.com).
> For more options, visit https://groups.google.com/d/optout.

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: pigpen newbie question

2014-09-11 Thread mbossenbroek via Clojure
That's a weird one :)

Couple of questions...

What version of pigpen are you using?
What are you using to compile & produce that output? It doesn't look like 
lein or gradle output.
What OS are you using?
Do you have a full sample project to repro?
Does your project have any other references? Something that might be 
pulling in a different version of instaparse?

There was an earlier version of pigpen that had a bad version of 
instaparse, but that was fixed long 
ago: https://github.com/Netflix/PigPen/issues/4

Sorry to answer your question with a bunch of questions, but I haven't seen 
that one before.

-Matt

On Thursday, September 11, 2014 5:16:45 PM UTC-7, Sunil Nandihalli wrote:
>
> Hi ,
>  I am trying to compile a simple clj file which does nothing apart from 
> requiring the pigpen name-space and it fails to compile with the following 
> error. Can anybody help?
>
> Attempting to call unbound fn: #'instaparse.combinators-source/cat
>
> the full stack trace is here. 
> https://gist.github.com/sunilnandihalli/b400e21552ca97038e56
>
> Thanks,
> Sunil.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: pigpen newbie question

2014-09-11 Thread Mark Engelberg
You're probably using Clojure 1.7.0 alpha 2, which introduced a new
function called "cat" into the core namespace, which overlaps with a
function in instaparse.

A couple nights ago, I updated instaparse to version 1.3.4, with an update
to deal with this change in alpha 2, but pigpen has not yet been updated to
use that version of instaparse.

You can either go back to a non-alpha release of Clojure, or wait for the
pigpen folks to update, or perhaps there is some leiningen-fu you can do in
the project.clj file to override the instaparse dependency loaded by pigpen
with instaparse 1.3.4.

On Thu, Sep 11, 2014 at 5:16 PM, Sunil S Nandihalli <
sunil.nandiha...@gmail.com> wrote:

> Hi ,
>  I am trying to compile a simple clj file which does nothing apart from
> requiring the pigpen name-space and it fails to compile with the following
> error. Can anybody help?
>
> Attempting to call unbound fn: #'instaparse.combinators-source/cat
>
> the full stack trace is here.
> https://gist.github.com/sunilnandihalli/b400e21552ca97038e56
>
> Thanks,
> Sunil.
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


pigpen newbie question

2014-09-11 Thread Sunil S Nandihalli
Hi ,
 I am trying to compile a simple clj file which does nothing apart from
requiring the pigpen name-space and it fails to compile with the following
error. Can anybody help?

Attempting to call unbound fn: #'instaparse.combinators-source/cat

the full stack trace is here.
https://gist.github.com/sunilnandihalli/b400e21552ca97038e56

Thanks,
Sunil.

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: newbie question: how to include external libraries from Leiningen REPL

2013-11-07 Thread Qiu Xiafei
you may have a look at alembic: https://github.com/pallet/alembic

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: newbie question: how to include external libraries from Leiningen REPL

2013-11-07 Thread Sean Corfield
On Thu, Nov 7, 2013 at 5:18 AM, Starry SHI  wrote:
> Hi, I am new to clojure and I find lein REPL very convenient to use. But I
> have one question: in REPL, how to include functions defined in other
> libraries and call them in my clojure code?

As Marshall indicated, you need to edit your project.clj file - which
in turn means you need to have such a file, which you create with:
lein new myproject (or whatever you want to call it). Leiningen will
create a folder called myproject containing a bunch of stuff including
project.clj. If you run `lein repl` inside the myproject folder, it
will have access to whatever libraries you've added to project.clj.

Example:

> lein new math
Generating a project called math based on the 'default' template.
To see other templates (app, lein plugin, etc), try `lein help new`.
> cd math
> cat project.clj
(defproject math "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME";
  :license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.5.1"]])

See :dependencies? That's where you'll add new libraries. You asked
about clojure.contrib.math but that is old and no longer maintained,
so for contrib libraries, consult this page:

http://dev.clojure.org/display/community/Where+Did+Clojure.Contrib+Go

(for other non-core/non-contrib libraries, you would search
http://clojars.org as Marshall indicated)

You'll see:

* clojure.contrib.math
  * Migrated to clojure.math.numeric-tower - lead Mark Engelberg.
  * Status: latest build status, latest release on Maven, report bugs.

And if you go to https://github.com/clojure/math.numeric-tower/ (which
is where clojure.math.numeric-tower links to) you'll see:

Leiningen dependency information:

[org.clojure/math.numeric-tower "0.0.2"]

So we'll edit project.clj to include that... and get:

> cat project.clj
(defproject math "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME";
  :license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.5.1"]
 [org.clojure/math.numeric-tower "0.0.2"]])

Be careful about the brackets!

Now we'll start a repl:

> lein repl
...
user=> (require '[clojure.math.numeric-tower :as math])
nil
user=> (math/sqrt 1234)
35.12833614050059
user=>

Hope that helps?
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: newbie question: how to include external libraries from Leiningen REPL

2013-11-07 Thread Mars0i
I'm pretty new, also.  The Leiningen documentation that's easy to find has 
all of the information you need ... but it's not easy to sort out at 
first.  Cedric Greevey gives the answer for standard libraries that usually 
come with Clojure.  For others, I suggest:

Find the library name and version number that you want at clojars.org.

Create a project directory with a command like:
lein new app newdir

Then edit newdir/project.clj:
Add 
[libname-from-clojars.org "version number"]
inside the outer pair of brackets [] after :dependencies,
and save.

Then change to the newdir directory and enter
lein deps

Then start the lein repl.

Then follow Cedric's instructions.
 
On Thursday, November 7, 2013 7:18:30 AM UTC-6, Starry SHI wrote:
>
> Hi, I am new to clojure and I find lein REPL very convenient to use. But I 
> have one question: in REPL, how to include functions defined in other 
> libraries and call them in my clojure code?
>
> For example, my code need to call square root function defined in 
> clojure.contrib.math (included in clojure-contrib.jar). Can anyone tell me 
> how to include this jar file from lein repl, so that my code can call sqrt 
> function?
>
> Thank you! 
>

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: newbie question: how to include external libraries from Leiningen REPL

2013-11-07 Thread Cedric Greevey
Assuming the Java or Clojure library is on your classpath, it *should* be
usable from the REPL.

(import '[java.library SomeClass])

(.foo (SomeClass. 42))

(require '[clojure.contrib.math :as m])

(m/sqrt 42.0)

or whatever.

(Didn't this exact question just get asked by someone five minutes ago?
Even looking for the same math function.)



On Thu, Nov 7, 2013 at 8:18 AM, Starry SHI  wrote:

> Hi, I am new to clojure and I find lein REPL very convenient to use. But I
> have one question: in REPL, how to include functions defined in other
> libraries and call them in my clojure code?
>
> For example, my code need to call square root function defined in
> clojure.contrib.math (included in clojure-contrib.jar). Can anyone tell me
> how to include this jar file from lein repl, so that my code can call sqrt
> function?
>
> Thank you!
>
> --
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


newbie question: how to include external libraries from Leiningen REPL

2013-11-07 Thread Starry SHI
Hi, I am new to clojure and I find lein REPL very convenient to use. But I 
have one question: in REPL, how to include functions defined in other 
libraries and call them in my clojure code?

For example, my code need to call square root function defined in 
clojure.contrib.math (included in clojure-contrib.jar). Can anyone tell me 
how to include this jar file from lein repl, so that my code can call sqrt 
function?

Thank you! 

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Newbie question: How to add external clojure jars properly in Eclipse.

2013-10-21 Thread Christopher Bird
Laurent, that is outstanding. Thank you so much. Yup, I am working from the 
particular to the general here, so having a working example really makes a 
big difference.
I must say that this is a really helpful community. Thanks evryone

Chris

On Monday, October 21, 2013 7:15:38 AM UTC-5, Laurent PETIT wrote:
>
> Hello Christopher, 
>
> I will try to address exactly your example, with Counterclockwise, and 
> hopefully you'll get the general view of how to do things on the go. 
>
> So you want to instanciate a new namespace like this : 
>
> (ns play.xml-example 
> (:require [clojure.zip :as zip] 
> [clojure.data.zip :as zf] 
> [clojure.xml :as xml]) 
> (:use clojure.data.zip.xml)) 
>
>
> Code be taken from examples on the web generally have a lot of 
> assumptions. Here, for instance, the assumption was that 
> clojure.data.zip namespace is already in the classpath, and for this 
> to happen, it should either be shipped with the clojure library (which 
> it isn't), or installed in the classpath via one of the declared 
> dependencies of your project. 
>
> A small search of the String "clojure.data.zip" in Google directs me 
> to https://github.com/clojure/data.zip/  (2d search entry for me, but 
> this could vary for you) 
> This page is the README for project "clojure.data.zip", with a 
> "Releases and Dependency Information" section. 
> This section contains : 
>
>   Leiningen dependency information: 
>   [org.clojure/data.zip "0.1.1"] 
>
> There we are: you need the artifact named data.zip (member of the 
> artifacts group named org.clojure). Its current stable version is 
> 0.1.1. Those artifact id + group id + version are called "coordinates" 
> in Leiningen. Leiningen inherits this terminology from Maven 
> (http://www.apache.org) which is a Java project management / build 
> tools with which Leiningen shares the way to store / retrieve 
> "artifacts" from Internet. 
>
> The easiest way to continue from here, if you already have Eclipse + 
> Counterclockwise installed, is to just create a new Clojure project by 
> following CCW's documentation for creating a new project ( 
>
> https://github.com/laurentpetit/ccw/blob/master/doc/src/main/asciidoc/documentation.adoc#create-a-new-project
>  
> ) 
>
> In the `Package Explorer View` (by default opened on the left side of 
> the editors) you should see your project. 
>
> Open the project's file `project.clj`, it should look like this: 
>
> project.clj 
>  
> (defproject foo "0.1.0-SNAPSHOT" 
>   :description "FIXME: write description" 
>   :url "http://example.com/FIXME"; 
>   :license {:name "Eclipse Public License" 
> :url "http://www.eclipse.org/legal/epl-v10.html"} 
>   :dependencies [[org.clojure/clojure "1.5.1"]]) 
>  
>
> You should also see inside your project a node named `Leiningen 
> Dependencies`. If you expand it, you should see the clojure jar 
> (`clojure-1.5.1.jar`) 
>
> Add the dependency for `clojure.data.zip` so that it then looks like this: 
>
> project.clj 
>  
> (defproject foo "0.1.0-SNAPSHOT" 
>   :description "FIXME: write description" 
>   :url "http://example.com/FIXME"; 
>   :license {:name "Eclipse Public License" 
> :url "http://www.eclipse.org/legal/epl-v10.html"} 
>   :dependencies [[org.clojure/clojure "1.5.1"] 
>  [org.clojure/data.zip "0.1.1"]]) ; <1> 
>  
>
> <1> Addition of the clojure.data.zip dependency 
>
> Save the `project.clj` file. 
>
> Eclipse will work a little bit in the background to fetch the 
> dependency from Internet (and the next times, from a hidden cached 
> location in `~/.m2/repository`). 
> And then you should see inside the `Leiningen Dependencies` project 
> node a new entry: `data.zip-0.1.1.jar` 
>
> Now is time to start a REPL and play : in your project's contextual 
> menu, select `Run as > Clojure Application`. A REPL will open, you'll 
> be able to paste the namespace declaration into it ( Ctrl + Enter to 
> send for evaluation): 
>
>  
> ;; Clojure 1.5.1 
> => (ns play.xml-example 
>(:require [clojure.zip :as zip] 
>[clojure.data.zip :as zf] 
>[clojure.xml :as xml]) 
>(:use clojure.data.zip.xml)) 
> nil 
>  
>
> HTH, 
>
> -- 
> Laurent 
>
>
>
>
> 2013/10/18 Christopher Bird >: 
> > I know this is a pretty old thread, but my questions are quite 
> > similar/related, so I figured here would be a good place for them. 
> > 
> > I am seriously struggling with both the Eclipse/Kepler-CounterClockwise 
> > version in general and the command prompt versions of lein. 
> > My major issue is how to tell the environments which libraries, etc. to 
> > load. For example, one of the libraries I really want to use is the 
> whole 
> > zipper approach for dealing with xml. 
> > 
> > From this location http://grokbase.com/t/gg/clojure/11ccz70h0y/xml-zipI see 
> > the following code: 
> > 
> > (ns play.xml-example 
> > (:require [clojure.zip :as zip] 
> > [clojure.data.zip :as zf] 
> > [clojure.xml :as xml]) 
> > (:use cloj

Re: Newbie question: How to add external clojure jars properly in Eclipse.

2013-10-21 Thread Laurent PETIT
Hello Christopher,

I will try to address exactly your example, with Counterclockwise, and
hopefully you'll get the general view of how to do things on the go.

So you want to instanciate a new namespace like this :

(ns play.xml-example
(:require [clojure.zip :as zip]
[clojure.data.zip :as zf]
[clojure.xml :as xml])
(:use clojure.data.zip.xml))


Code be taken from examples on the web generally have a lot of
assumptions. Here, for instance, the assumption was that
clojure.data.zip namespace is already in the classpath, and for this
to happen, it should either be shipped with the clojure library (which
it isn't), or installed in the classpath via one of the declared
dependencies of your project.

A small search of the String "clojure.data.zip" in Google directs me
to https://github.com/clojure/data.zip/  (2d search entry for me, but
this could vary for you)
This page is the README for project "clojure.data.zip", with a
"Releases and Dependency Information" section.
This section contains :

  Leiningen dependency information:
  [org.clojure/data.zip "0.1.1"]

There we are: you need the artifact named data.zip (member of the
artifacts group named org.clojure). Its current stable version is
0.1.1. Those artifact id + group id + version are called "coordinates"
in Leiningen. Leiningen inherits this terminology from Maven
(http://www.apache.org) which is a Java project management / build
tools with which Leiningen shares the way to store / retrieve
"artifacts" from Internet.

The easiest way to continue from here, if you already have Eclipse +
Counterclockwise installed, is to just create a new Clojure project by
following CCW's documentation for creating a new project (
https://github.com/laurentpetit/ccw/blob/master/doc/src/main/asciidoc/documentation.adoc#create-a-new-project
)

In the `Package Explorer View` (by default opened on the left side of
the editors) you should see your project.

Open the project's file `project.clj`, it should look like this:

project.clj

(defproject foo "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME";
  :license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.5.1"]])


You should also see inside your project a node named `Leiningen
Dependencies`. If you expand it, you should see the clojure jar
(`clojure-1.5.1.jar`)

Add the dependency for `clojure.data.zip` so that it then looks like this:

project.clj

(defproject foo "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME";
  :license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.5.1"]
 [org.clojure/data.zip "0.1.1"]]) ; <1>


<1> Addition of the clojure.data.zip dependency

Save the `project.clj` file.

Eclipse will work a little bit in the background to fetch the
dependency from Internet (and the next times, from a hidden cached
location in `~/.m2/repository`).
And then you should see inside the `Leiningen Dependencies` project
node a new entry: `data.zip-0.1.1.jar`

Now is time to start a REPL and play : in your project's contextual
menu, select `Run as > Clojure Application`. A REPL will open, you'll
be able to paste the namespace declaration into it ( Ctrl + Enter to
send for evaluation):


;; Clojure 1.5.1
=> (ns play.xml-example
   (:require [clojure.zip :as zip]
   [clojure.data.zip :as zf]
   [clojure.xml :as xml])
   (:use clojure.data.zip.xml))
nil


HTH,

-- 
Laurent




2013/10/18 Christopher Bird :
> I know this is a pretty old thread, but my questions are quite
> similar/related, so I figured here would be a good place for them.
>
> I am seriously struggling with both the Eclipse/Kepler-CounterClockwise
> version in general and the command prompt versions of lein.
> My major issue is how to tell the environments which libraries, etc. to
> load. For example, one of the libraries I really want to use is the whole
> zipper approach for dealing with xml.
>
> From this location http://grokbase.com/t/gg/clojure/11ccz70h0y/xml-zip I see
> the following code:
>
> (ns play.xml-example
> (:require [clojure.zip :as zip]
> [clojure.data.zip :as zf]
> [clojure.xml :as xml])
> (:use clojure.data.zip.xml))
> And this is what I get:
>
> C:\Users\Christopher Bird>lein repl
> nREPL server started on port 64784 on host 127.0.0.1
> REPL-y 0.2.1
> Clojure 1.5.1
> Docs: (doc function-name-here)
>   (find-doc "part-of-name-here")
>   Source: (source function-name-here)
>  Javadoc: (javadoc java-object-or-class-here)
> Exit: Control+D or (exit) or (quit)
>
> user=> (ns play.xml-example
>   #_=> (:require [clojure.zip :as zip]
>   #_=> [clojure.data.zip :as zf]
>   #_=> [clojure.xml :as xml]
>   #_=> )
>   #_=> (:use clojure.data.zip.xml))
>
> FileNotFoundException Could not locate clojure/data/zip__init.class or
> cloju

Re: Newbie question: How to add external clojure jars properly in Eclipse.

2013-10-19 Thread John Mastro
> John, thanks. Not a stupid question at all. When learning a new language, a 
> new environment, and using an unfamiliar OS, there are so many moving parts 
> that it is sometimes hard to know where to begin when tracking stuff down. My 
> old and favorite line here is that "signposts are generally made by people 
> who know the lay of the land"..
> So please keep the advice coming.


Were you able to get it working after setting :dependencies?

To expand a bit on what's going on: Part of what Leiningen does for you is 
manage your dependencies (including Clojure itself, which is very cool). It 
will both install them and arrange for the correct classpath to be in effect 
when you run e.g. 'lein repl' or 'lein run' from your project directory. You 
only need to tell Leiningen about your direct dependencies - it will 
automatically handle their dependencies as well. 

I'd recommend taking a look at Leiningen's official tutorial if you haven't 
already:
https://github.com/technomancy/leiningen/blob/stable/doc/TUTORIAL.md

I've never used Eclipse so I can't be any help there. 

- John

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Newbie question: How to add external clojure jars properly in Eclipse.

2013-10-19 Thread Christopher Bird
John, thanks. Not a stupid question at all. When learning a new language, a 
new environment, and using an unfamiliar OS, there are so many moving parts 
that it is sometimes hard to know where to begin when tracking stuff down. 
My old and favorite line here is that "signposts are generally made by 
people who know the lay of the land"..
So please keep the advice coming.

Chris

On Friday, October 18, 2013 10:16:38 AM UTC-5, John Mastro wrote:
>
> > So, clearly I need to get  the libs onto the classpath. The questions 
> are what libs, where and how? 
>
> Forgive me if this is a stupid question, but have you already listed the 
> dependency coordinates under the :dependencies key of your project.clj? 
>
> Leiningen has a sample project.clj here: 
> https://github.com/technomancy/leiningen/blob/master/sample.project.clj 
>
> You're unlikely to need most of the options - just take a look at 
> :dependencies. Each project will list the appropriate coordinate vector 
> (e.g. [some/project "1.0.0"]) on their project page and/or GitHub repo. 
>
> - John

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Newbie question: How to add external clojure jars properly in Eclipse.

2013-10-18 Thread John Mastro
> So, clearly I need to get  the libs onto the classpath. The questions are 
> what libs, where and how?

Forgive me if this is a stupid question, but have you already listed the 
dependency coordinates under the :dependencies key of your project.clj?

Leiningen has a sample project.clj here: 
https://github.com/technomancy/leiningen/blob/master/sample.project.clj

You're unlikely to need most of the options - just take a look at 
:dependencies. Each project will list the appropriate coordinate vector (e.g. 
[some/project "1.0.0"]) on their project page and/or GitHub repo.

- John

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Newbie question: How to add external clojure jars properly in Eclipse.

2013-10-18 Thread Josh Kamau
Install counterclockwise plugin on your eclipse. Then import your project
into eclipse. There right click the project and there is something like
"Convert to leiningen project" .

Hope that helps.
Josh.


On Fri, Oct 18, 2013 at 5:41 PM, Christopher Bird wrote:

> Josh, thanks for replying. The code sample was from my batch lein and not
> the counterclockwise version. So I am clearly still totally messed up[!
>
> C
>
>
> On Friday, October 18, 2013 9:11:54 AM UTC-5, Josh Kamau wrote:
>
>> I find it easier to let leiningen handle the dependencies.  Eclipse via
>> counterclockwise plugin adds dependencies declared in project.clj to the
>> classpath.
>>
>> Josh
>>
>>
>> On Fri, Oct 18, 2013 at 4:42 PM, Christopher Bird wrote:
>>
>>> I know this is a pretty old thread, but my questions are quite
>>> similar/related, so I figured here would be a good place for them.
>>>
>>> I am seriously struggling with both the Eclipse/Kepler-**CounterClockwise
>>> version in general and the command prompt versions of lein.
>>> My major issue is how to tell the environments which libraries, etc. to
>>> load. For example, one of the libraries I really want to use is the whole
>>> zipper approach for dealing with xml.
>>>
>>> From this location 
>>> http://grokbase.com/t/gg/**clojure/11ccz70h0y/xml-zipI
>>>  see the following code:
>>>
>>> (ns play.xml-example
>>> (:require [clojure.zip :as zip]
>>> [clojure.data.zip :as zf]
>>> [clojure.xml :as xml])
>>> (:use clojure.data.zip.xml))
>>> And this is what I get:
>>>
>>> C:\Users\Christopher Bird>lein repl
>>> nREPL server started on port 64784 on host 127.0.0.1
>>> REPL-y 0.2.1
>>> Clojure 1.5.1
>>> Docs: (doc function-name-here)
>>>   (find-doc "part-of-name-here")
>>>   Source: (source function-name-here)
>>>  Javadoc: (javadoc java-object-or-class-here)
>>> Exit: Control+D or (exit) or (quit)
>>>
>>> user=> (ns play.xml-example
>>>   #_=> (:require [clojure.zip :as zip]
>>>   #_=> [clojure.data.zip :as zf]
>>>   #_=> [clojure.xml :as xml]
>>>   #_=> )
>>>   #_=> (:use clojure.data.zip.xml))
>>>
>>> FileNotFoundException Could not locate clojure/data/zip__init.class or
>>> clojure/data/zip.clj on classpath:   clojure.lang
>>> .RT.load (RT.java:443)
>>> user=>
>>>  So, clearly I need to get  the libs onto the classpath. The questions
>>> are what libs, where and how?
>>>
>>> Thanks in advance for any/all help
>>>
>>> Chris
>>> On Wednesday, September 7, 2011 2:09:01 PM UTC-5, Joseph Li wrote:

 hi all,

 I have a bare bone Clojure project created in Eclipse with
 Counterclockwise plugin and am trying to (use clojure.java.jdbc).
  I tried adding the jar file downloaded from Maven repo to the
 project's build path but everytime it runs the (use) line from the
 repl it will  give a ClassNotFoundException.

 I ended up downloading the source and put it right there along with my
 own but still have to fully qualify with the ns name to use anything
 there.

 Is Maven/Leiningen pretty much the only way to obtain clojure lib
 properly?

 Thanks,
 Joseph

  --
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To post to this group, send email to clo...@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+u...@**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 unsubscribe from this group and stop receiving emails from it, send
>>> an email to clojure+u...@**googlegroups.com.
>>>
>>> For more options, visit 
>>> https://groups.google.com/**groups/opt_out
>>> .
>>>
>>
>>  --
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
-- 
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 - ple

Re: Newbie question: How to add external clojure jars properly in Eclipse.

2013-10-18 Thread Christopher Bird
Josh, thanks for replying. The code sample was from my batch lein and not 
the counterclockwise version. So I am clearly still totally messed up[!

C

On Friday, October 18, 2013 9:11:54 AM UTC-5, Josh Kamau wrote:
>
> I find it easier to let leiningen handle the dependencies.  Eclipse via 
> counterclockwise plugin adds dependencies declared in project.clj to the 
> classpath.
>
> Josh
>
>
> On Fri, Oct 18, 2013 at 4:42 PM, Christopher Bird 
> 
> > wrote:
>
>> I know this is a pretty old thread, but my questions are quite 
>> similar/related, so I figured here would be a good place for them.
>>
>> I am seriously struggling with both the Eclipse/Kepler-CounterClockwise 
>> version in general and the command prompt versions of lein. 
>> My major issue is how to tell the environments which libraries, etc. to 
>> load. For example, one of the libraries I really want to use is the whole 
>> zipper approach for dealing with xml.
>>
>> From this location http://grokbase.com/t/gg/clojure/11ccz70h0y/xml-zip I 
>> see the following code:
>>
>> (ns play.xml-example
>> (:require [clojure.zip :as zip]
>> [clojure.data.zip :as zf]
>> [clojure.xml :as xml])
>> (:use clojure.data.zip.xml))
>> And this is what I get:
>>
>> C:\Users\Christopher Bird>lein repl
>> nREPL server started on port 64784 on host 127.0.0.1
>> REPL-y 0.2.1
>> Clojure 1.5.1
>> Docs: (doc function-name-here)
>>   (find-doc "part-of-name-here")
>>   Source: (source function-name-here)
>>  Javadoc: (javadoc java-object-or-class-here)
>> Exit: Control+D or (exit) or (quit)
>>
>> user=> (ns play.xml-example
>>   #_=> (:require [clojure.zip :as zip]
>>   #_=> [clojure.data.zip :as zf]
>>   #_=> [clojure.xml :as xml]
>>   #_=> )
>>   #_=> (:use clojure.data.zip.xml))
>>
>> FileNotFoundException Could not locate clojure/data/zip__init.class or 
>> clojure/data/zip.clj on classpath:   clojure.lang
>> .RT.load (RT.java:443)
>> user=>
>>  So, clearly I need to get  the libs onto the classpath. The questions 
>> are what libs, where and how?
>>
>> Thanks in advance for any/all help
>>
>> Chris
>> On Wednesday, September 7, 2011 2:09:01 PM UTC-5, Joseph Li wrote:
>>>
>>> hi all, 
>>>
>>> I have a bare bone Clojure project created in Eclipse with 
>>> Counterclockwise plugin and am trying to (use clojure.java.jdbc). 
>>>  I tried adding the jar file downloaded from Maven repo to the 
>>> project's build path but everytime it runs the (use) line from the 
>>> repl it will  give a ClassNotFoundException. 
>>>
>>> I ended up downloading the source and put it right there along with my 
>>> own but still have to fully qualify with the ns name to use anything 
>>> there. 
>>>
>>> Is Maven/Leiningen pretty much the only way to obtain clojure lib 
>>> properly? 
>>>
>>> Thanks, 
>>> Joseph 
>>>
>>>  -- 
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send an 
>> email to clojure+u...@googlegroups.com .
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Newbie question: How to add external clojure jars properly in Eclipse.

2013-10-18 Thread Josh Kamau
I find it easier to let leiningen handle the dependencies.  Eclipse via
counterclockwise plugin adds dependencies declared in project.clj to the
classpath.

Josh


On Fri, Oct 18, 2013 at 4:42 PM, Christopher Bird wrote:

> I know this is a pretty old thread, but my questions are quite
> similar/related, so I figured here would be a good place for them.
>
> I am seriously struggling with both the Eclipse/Kepler-CounterClockwise
> version in general and the command prompt versions of lein.
> My major issue is how to tell the environments which libraries, etc. to
> load. For example, one of the libraries I really want to use is the whole
> zipper approach for dealing with xml.
>
> From this location http://grokbase.com/t/gg/clojure/11ccz70h0y/xml-zip I
> see the following code:
>
> (ns play.xml-example
> (:require [clojure.zip :as zip]
> [clojure.data.zip :as zf]
> [clojure.xml :as xml])
> (:use clojure.data.zip.xml))
> And this is what I get:
>
> C:\Users\Christopher Bird>lein repl
> nREPL server started on port 64784 on host 127.0.0.1
> REPL-y 0.2.1
> Clojure 1.5.1
> Docs: (doc function-name-here)
>   (find-doc "part-of-name-here")
>   Source: (source function-name-here)
>  Javadoc: (javadoc java-object-or-class-here)
> Exit: Control+D or (exit) or (quit)
>
> user=> (ns play.xml-example
>   #_=> (:require [clojure.zip :as zip]
>   #_=> [clojure.data.zip :as zf]
>   #_=> [clojure.xml :as xml]
>   #_=> )
>   #_=> (:use clojure.data.zip.xml))
>
> FileNotFoundException Could not locate clojure/data/zip__init.class or
> clojure/data/zip.clj on classpath:   clojure.lang
> .RT.load (RT.java:443)
> user=>
>  So, clearly I need to get  the libs onto the classpath. The questions are
> what libs, where and how?
>
> Thanks in advance for any/all help
>
> Chris
> On Wednesday, September 7, 2011 2:09:01 PM UTC-5, Joseph Li wrote:
>>
>> hi all,
>>
>> I have a bare bone Clojure project created in Eclipse with
>> Counterclockwise plugin and am trying to (use clojure.java.jdbc).
>>  I tried adding the jar file downloaded from Maven repo to the
>> project's build path but everytime it runs the (use) line from the
>> repl it will  give a ClassNotFoundException.
>>
>> I ended up downloading the source and put it right there along with my
>> own but still have to fully qualify with the ns name to use anything
>> there.
>>
>> Is Maven/Leiningen pretty much the only way to obtain clojure lib
>> properly?
>>
>> Thanks,
>> Joseph
>>
>>  --
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Newbie question: How to add external clojure jars properly in Eclipse.

2013-10-18 Thread Christopher Bird
I know this is a pretty old thread, but my questions are quite 
similar/related, so I figured here would be a good place for them.

I am seriously struggling with both the Eclipse/Kepler-CounterClockwise 
version in general and the command prompt versions of lein. 
My major issue is how to tell the environments which libraries, etc. to 
load. For example, one of the libraries I really want to use is the whole 
zipper approach for dealing with xml.

>From this location http://grokbase.com/t/gg/clojure/11ccz70h0y/xml-zip I 
see the following code:

(ns play.xml-example
(:require [clojure.zip :as zip]
[clojure.data.zip :as zf]
[clojure.xml :as xml])
(:use clojure.data.zip.xml))
And this is what I get:

C:\Users\Christopher Bird>lein repl
nREPL server started on port 64784 on host 127.0.0.1
REPL-y 0.2.1
Clojure 1.5.1
Docs: (doc function-name-here)
  (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
Exit: Control+D or (exit) or (quit)

user=> (ns play.xml-example
  #_=> (:require [clojure.zip :as zip]
  #_=> [clojure.data.zip :as zf]
  #_=> [clojure.xml :as xml]
  #_=> )
  #_=> (:use clojure.data.zip.xml))

FileNotFoundException Could not locate clojure/data/zip__init.class or 
clojure/data/zip.clj on classpath:   clojure.lang
.RT.load (RT.java:443)
user=>
 So, clearly I need to get  the libs onto the classpath. The questions are 
what libs, where and how?

Thanks in advance for any/all help

Chris
On Wednesday, September 7, 2011 2:09:01 PM UTC-5, Joseph Li wrote:
>
> hi all, 
>
> I have a bare bone Clojure project created in Eclipse with 
> Counterclockwise plugin and am trying to (use clojure.java.jdbc). 
>  I tried adding the jar file downloaded from Maven repo to the 
> project's build path but everytime it runs the (use) line from the 
> repl it will  give a ClassNotFoundException. 
>
> I ended up downloading the source and put it right there along with my 
> own but still have to fully qualify with the ns name to use anything 
> there. 
>
> Is Maven/Leiningen pretty much the only way to obtain clojure lib 
> properly? 
>
> Thanks, 
> Joseph 
>
>

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: newbie question about symbols

2013-05-30 Thread Brian Craft
ah, thanks.

On Thursday, May 30, 2013 2:48:00 PM UTC-7, cjeris wrote:
>
> Commas are whitespace in Clojure.  If you are looking for the unquote 
> operator, it is ~.
>
> user=> (first `(~+ 5))
> #
>
> peace, Chris
>
>
> On Thu, May 30, 2013 at 5:42 PM, Brian Craft 
> > wrote:
>
>> What's up with the 3rd result here?
>>
>> user=> (symbol? +)
>> false
>> user=> (symbol? clojure.core/+)
>> false
>> user=> (symbol? (first `(,+ 5)))
>> true
>> user=> (first `(,+ 5))
>> clojure.core/+
>>
>>  -- 
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send an 
>> email to clojure+u...@googlegroups.com .
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>
>
> -- 
> Chris Jeris
> cje...@brightcove.com 
> freenode/twitter/github: ystael
>  

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: newbie question about symbols

2013-05-30 Thread Chris Jeris
Commas are whitespace in Clojure.  If you are looking for the unquote
operator, it is ~.

user=> (first `(~+ 5))
#

peace, Chris


On Thu, May 30, 2013 at 5:42 PM, Brian Craft  wrote:

> What's up with the 3rd result here?
>
> user=> (symbol? +)
> false
> user=> (symbol? clojure.core/+)
> false
> user=> (symbol? (first `(,+ 5)))
> true
> user=> (first `(,+ 5))
> clojure.core/+
>
>  --
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Chris Jeris
cje...@brightcove.com
freenode/twitter/github: ystael

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




newbie question about symbols

2013-05-30 Thread Brian Craft
What's up with the 3rd result here?

user=> (symbol? +)
false
user=> (symbol? clojure.core/+)
false
user=> (symbol? (first `(,+ 5)))
true
user=> (first `(,+ 5))
clojure.core/+

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Reducers newbie question

2013-04-27 Thread Stanislav Yurin
Indeed, that was my really bad example with 100.

On Saturday, April 27, 2013 4:19:07 PM UTC+3, Alan Busby wrote:
>
>
> On Sat, Apr 27, 2013 at 10:01 PM, Stanislav Yurin 
> 
> > wrote:
>
>> By the way, fold function has [n combinef reducef coll] implementation, 
>> where n is number of elements collection is folded by. 512 is just the 
>> default.
>>
>
> Yep I misspoke there, but it is still one of the tricks to be aware of.
>
> Lots of people do; 
> (->> (range 100)
>vec
>(r/filter even?)
>(r/fold +))
>
> And wonder why it's not running in parallel.
>

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Reducers newbie question

2013-04-27 Thread Alan Busby
On Sat, Apr 27, 2013 at 10:01 PM, Stanislav Yurin  wrote:

> By the way, fold function has [n combinef reducef coll] implementation,
> where n is number of elements collection is folded by. 512 is just the
> default.
>

Yep I misspoke there, but it is still one of the tricks to be aware of.

Lots of people do;
(->> (range 100)
   vec
   (r/filter even?)
   (r/fold +))

And wonder why it's not running in parallel.

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Reducers newbie question

2013-04-27 Thread Stanislav Yurin
Thanks Alan, looking into it.
By the way, fold function has [n combinef reducef coll] implementation, 
where n is number of elements collection is folded by. 512 is just the 
default.

On Saturday, April 27, 2013 3:51:39 PM UTC+3, Alan Busby wrote:
>
> On Sat, Apr 27, 2013 at 7:35 PM, Stanislav Yurin 
> 
> > wrote:
>
>> Actually, what I was trying to do, is to prototype multithreaded i/o 
>> operation via reducers. And then use fold to regulate number of concurrent 
>> operations.
>> But now something tells me I am doing not very clever thing.
>>
>
> I'm not entirely sure what you mean above, but I've been very happy using 
> reducers with I/O so far.
>
> Reducers just have a few tricks you need to be aware of first;
> 1. You wont get parallel processing unless the input is a vector.
> 2. Each thread gets ~512 elements each, so reducing a vector of 800 
> elements will only use two cores. 
> 3. How you aggregate your final result can greatly impact performance. 
> (Ex. (r/fold +) is fast, fold-into-vec is slower, etc)
>
> I wrote a library to use reducers over text files (input) and have found 
> it to be invaluable for working with giant TSV files.
> Link: https://github.com/thebusby/iota/
>
> I often then use fold-into-lazy-seq to write the output back to a file.
> Link: https://gist.github.com/thebusby/5472980
>
> Hope this helps! ;)
>

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Reducers newbie question

2013-04-27 Thread Alan Busby
On Sat, Apr 27, 2013 at 7:35 PM, Stanislav Yurin  wrote:

> Actually, what I was trying to do, is to prototype multithreaded i/o
> operation via reducers. And then use fold to regulate number of concurrent
> operations.
> But now something tells me I am doing not very clever thing.
>

I'm not entirely sure what you mean above, but I've been very happy using
reducers with I/O so far.

Reducers just have a few tricks you need to be aware of first;
1. You wont get parallel processing unless the input is a vector.
2. Each thread gets ~512 elements each, so reducing a vector of 800
elements will only use two cores.
3. How you aggregate your final result can greatly impact performance. (Ex.
(r/fold +) is fast, fold-into-vec is slower, etc)

I wrote a library to use reducers over text files (input) and have found it
to be invaluable for working with giant TSV files.
Link: https://github.com/thebusby/iota/

I often then use fold-into-lazy-seq to write the output back to a file.
Link: https://gist.github.com/thebusby/5472980

Hope this helps! ;)

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Reducers newbie question

2013-04-27 Thread Stanislav Yurin
Yep, thanks, my bad. I got the point.

Actually, what I was trying to do, is to prototype multithreaded i/o 
operation via reducers. And then use fold to regulate number of concurrent 
operations.
But now something tells me I am doing not very clever thing.

On Friday, April 26, 2013 5:27:46 PM UTC+3, Stanislav Yurin wrote:
>
> I was assuming that following code will fold in parallel, but it is 
> reduced sequentially
>
> (require '[clojure.core.reducers :as r])
> (defn test1 
> [x] 
> (Thread/sleep 1000) 
> (println (str "Finished:" x))
> x)
> (def xxx (r/map test1 (range 100)))
> (r/fold + xxx)
>
> What am I doing wrong?
> Thanks.
>

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Reducers newbie question

2013-04-26 Thread Jim - FooBar();

+1 ! I use 'fold-into-vec' regularly :)

Jim

On 26/04/13 18:07, Alan Busby wrote:

Some additional pointers here (this is a little old though);
http://www.thebusby.com/2012/07/tips-tricks-with-clojure-reducers.html


On Fri, Apr 26, 2013 at 11:51 PM, László Török > wrote:


Hi,

Not sure what you are trying to do, but xxx is a lazy seq, thus it
can only be consumed sequentially and fold falls back to reduce

You need a vector.

Las

Sent from my phone

On Apr 26, 2013 4:46 PM, "Stanislav Yurin" mailto:jusk...@gmail.com>> wrote:

I was assuming that following code will fold in parallel, but
it is reduced sequentially

(require '[clojure.core.reducers :as r])
(defn test1
[x]
(Thread/sleep 1000)
(println (str "Finished:" x))
x)
(def xxx (r/map test1 (range 100)))
(r/fold + xxx)

What am I doing wrong?
Thanks.
-- 
-- 
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 unsubscribe from this group and stop receiving emails from
it, send an email to clojure+unsubscr...@googlegroups.com
.
For more options, visit https://groups.google.com/groups/opt_out.


-- 
-- 
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 unsubscribe from this group and stop receiving emails from it,
send an email to clojure+unsubscr...@googlegroups.com
.
For more options, visit https://groups.google.com/groups/opt_out.



--
--
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 unsubscribe from this group and stop receiving emails from it, send 
an email to clojure+unsubscr...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.




--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Reducers newbie question

2013-04-26 Thread Alan Busby
Some additional pointers here (this is a little old though);
http://www.thebusby.com/2012/07/tips-tricks-with-clojure-reducers.html


On Fri, Apr 26, 2013 at 11:51 PM, László Török  wrote:

> Hi,
>
> Not sure what you are trying to do, but xxx is a lazy seq, thus it can
> only be consumed sequentially and fold falls back to reduce
>
> You need a vector.
>
> Las
>
> Sent from my phone
> On Apr 26, 2013 4:46 PM, "Stanislav Yurin"  wrote:
>
>> I was assuming that following code will fold in parallel, but it is
>> reduced sequentially
>>
>> (require '[clojure.core.reducers :as r])
>> (defn test1
>>  [x]
>> (Thread/sleep 1000)
>>  (println (str "Finished:" x))
>> x)
>> (def xxx (r/map test1 (range 100)))
>> (r/fold + xxx)
>>
>> What am I doing wrong?
>> Thanks.
>>
>> --
>> --
>> 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 unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>  --
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Reducers newbie question

2013-04-26 Thread László Török
Hi,

Not sure what you are trying to do, but xxx is a lazy seq, thus it can only
be consumed sequentially and fold falls back to reduce

You need a vector.

Las

Sent from my phone
On Apr 26, 2013 4:46 PM, "Stanislav Yurin"  wrote:

> I was assuming that following code will fold in parallel, but it is
> reduced sequentially
>
> (require '[clojure.core.reducers :as r])
> (defn test1
> [x]
> (Thread/sleep 1000)
> (println (str "Finished:" x))
> x)
> (def xxx (r/map test1 (range 100)))
> (r/fold + xxx)
>
> What am I doing wrong?
> Thanks.
>
> --
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Reducers newbie question

2013-04-26 Thread Stanislav Yurin
I was assuming that following code will fold in parallel, but it is reduced 
sequentially

(require '[clojure.core.reducers :as r])
(defn test1 
[x] 
(Thread/sleep 1000) 
(println (str "Finished:" x))
x)
(def xxx (r/map test1 (range 100)))
(r/fold + xxx)

What am I doing wrong?
Thanks.

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: newbie question regarding maps

2012-09-27 Thread Mond Ray
Thanks for the support and especially the examples.  I will be back when I 
bump into the next level of complexity ;-)

On Monday, 24 September 2012 12:04:42 UTC+2, Mond Ray wrote:
>
> I am playing around with maps and using wish lists as a learning tool. I 
> have a list of items in wish lists like this:
>
> user=> items
> [{:name "Item 1", :cost 20.0} {:name "Item 2", :cost 40.0}]
>
> user=> wiggle-items
> [{:name "Wiggle 1", :cost 20.0} {:name "Wiggle 2", :cost 40.0} [:name 
> "Item 3" :cost 10.0]]
>
> user=> (def wish-lists [
> {:name "WL1" :items items}
> {:name "WL2" :items wiggle-items}
> ]
> )
> #'user/wish-lists
>
> user=> wish-lists
> [{:name "WL1", :items [{:name "Item 1", :cost 20.0} {:name "Item 2", :cost 
> 40.0}]} {:name "WL2", :items [{:name "Wiggle 1", :cost 20.0} {:name "Wiggle 
> 2", :cost 40.0} [:name "Item 3" :cost 10.0]]}]
>
> ---
>
> I now want to add an item to one of the Wish Lists but am struggling with 
> assoc and assoc-in (which seems to be the one I need).
>
> ---
>
> user=> (def new-wi (conj wiggle-items [ :name "Item 3" :cost 10.0 ]))
>
> #'user/new-wi
>
> user=> (assoc-in wish-lists [:name "WL1"] [:name "WL1" :items new-wi])
> IllegalArgumentException Key must be integer 
> clojure.lang.APersistentVector.assoc (APersistentVector.java:312)
>
>
> As you can see the REPL gives me an error stating that the keys must be 
> Integers. Is that right?  Or is my call process faulty?
>
> Thanks in advance for your support.
>
>
> ray
>

-- 
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: newbie question regarding maps

2012-09-26 Thread Timo Mihaljov
On 24.09.2012 13:04, Mond Ray wrote:
> user=> wish-lists
> [{:name "WL1", :items [{:name "Item 1", :cost 20.0} {:name "Item 2",
> :cost 40.0}]} {:name "WL2", :items [{:name "Wiggle 1", :cost 20.0}
> {:name "Wiggle 2", :cost 40.0} [:name "Item 3" :cost 10.0]]}]

> user=> (assoc-in wish-lists [:name "WL1"] [:name "WL1" :items new-wi])
> IllegalArgumentException Key must be integer
> clojure.lang.APersistentVector.assoc (APersistentVector.java:312)

`assoc-in` navigates nested data structures by keys. Like George said,
vectors' keys are integer indices, so you'd have to use `[0]` as the
path to refer to the first wish list. To navigate the data structure
using list names, change your `wish-lists` structure into a map with the
names as keys.

(def wish-lists {"WL1" [{:name "Item 1", :cost 20.0}
{:name "Item 2", :cost 40.0}]
 "WL2" [{:name "Wiggle 1", :cost 20.0}
{:name "Wiggle 2", :cost 40.0}]})

`assoc-in` is for adding new key-value pairs to a map, so it isn't quite
what you need to append to the wish list vector. There's a more generic
function called `update-in`, which takes a function to update the thing
at the end of the path. `conj` appends items to a vector, so that's what
you should use as the update function.

(update-in wish-lists ["WL1"] conj {:name "Item 3" :cost 10.0})
;= {"WL1" [{:name "Item 1", :cost 20.0}
   {:name "Item 2", :cost 40.0}
   {:name "Item 3", :cost 10.0}]
"WL2" [{:name "Wiggle 1", :cost 20.0}
   {:name "Wiggle 2", :cost 40.0}]}

Hope this helps,
-- 
Timo

-- 
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: newbie question regarding maps

2012-09-26 Thread vxm
(defn new-item-ks [wlists wlist-name]
  (first
   (keep-indexed #(when (= (:name %2) wlist-name)
[%1 :items (count (:items %2))])
wlists)))


(assoc-in wish-lists (new-item-ks wish-lists "WL2")
  {:name "Item 3" :cost 10.0})


On Monday, September 24, 2012 1:04:42 PM UTC+3, Mond Ray wrote:
>
> I am playing around with maps and using wish lists as a learning tool. I 
> have a list of items in wish lists like this:
>
> user=> items
> [{:name "Item 1", :cost 20.0} {:name "Item 2", :cost 40.0}]
>
> user=> wiggle-items
> [{:name "Wiggle 1", :cost 20.0} {:name "Wiggle 2", :cost 40.0} [:name 
> "Item 3" :cost 10.0]]
>
> user=> (def wish-lists [
> {:name "WL1" :items items}
> {:name "WL2" :items wiggle-items}
> ]
> )
> #'user/wish-lists
>
> user=> wish-lists
> [{:name "WL1", :items [{:name "Item 1", :cost 20.0} {:name "Item 2", :cost 
> 40.0}]} {:name "WL2", :items [{:name "Wiggle 1", :cost 20.0} {:name "Wiggle 
> 2", :cost 40.0} [:name "Item 3" :cost 10.0]]}]
>
> ---
>
> I now want to add an item to one of the Wish Lists but am struggling with 
> assoc and assoc-in (which seems to be the one I need).
>
> ---
>
> user=> (def new-wi (conj wiggle-items [ :name "Item 3" :cost 10.0 ]))
>
> #'user/new-wi
>
> user=> (assoc-in wish-lists [:name "WL1"] [:name "WL1" :items new-wi])
> IllegalArgumentException Key must be integer 
> clojure.lang.APersistentVector.assoc (APersistentVector.java:312)
>
>
> As you can see the REPL gives me an error stating that the keys must be 
> Integers. Is that right?  Or is my call process faulty?
>
> Thanks in advance for your support.
>
>
> ray
>

-- 
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: newbie question regarding maps

2012-09-25 Thread George Oliver


On Monday, September 24, 2012 3:04:42 AM UTC-7, Mond Ray wrote:
>
>
> As you can see the REPL gives me an error stating that the keys must be 
> Integers. Is that right?  Or is my call process faulty?
>
>
I think the problem is that wish-lists is a vector, so you need a key for 
the vector first (e.g. 0, 1. etc.) in assoc-in. That's what the error is 
saying. 

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

newbie question regarding maps

2012-09-25 Thread Mond Ray
I am playing around with maps and using wish lists as a learning tool. I 
have a list of items in wish lists like this:

user=> items
[{:name "Item 1", :cost 20.0} {:name "Item 2", :cost 40.0}]

user=> wiggle-items
[{:name "Wiggle 1", :cost 20.0} {:name "Wiggle 2", :cost 40.0} [:name "Item 
3" :cost 10.0]]

user=> (def wish-lists [
{:name "WL1" :items items}
{:name "WL2" :items wiggle-items}
]
)
#'user/wish-lists

user=> wish-lists
[{:name "WL1", :items [{:name "Item 1", :cost 20.0} {:name "Item 2", :cost 
40.0}]} {:name "WL2", :items [{:name "Wiggle 1", :cost 20.0} {:name "Wiggle 
2", :cost 40.0} [:name "Item 3" :cost 10.0]]}]

---

I now want to add an item to one of the Wish Lists but am struggling with 
assoc and assoc-in (which seems to be the one I need).

---

user=> (def new-wi (conj wiggle-items [ :name "Item 3" :cost 10.0 ]))

#'user/new-wi

user=> (assoc-in wish-lists [:name "WL1"] [:name "WL1" :items new-wi])
IllegalArgumentException Key must be integer 
clojure.lang.APersistentVector.assoc (APersistentVector.java:312)


As you can see the REPL gives me an error stating that the keys must be 
Integers. Is that right?  Or is my call process faulty?

Thanks in advance for your support.


ray

-- 
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: newbie question on namespaces and reference resources

2012-08-17 Thread Hugo Estrada
Thanks for answering both questions. I believe I saw some musical package,
so maybe I will look at that code. Thanks so much :)

On Fri, Aug 17, 2012 at 7:20 PM, Stephen Compall
wrote:

> On Sun, 2012-08-12 at 19:55 -0700, Hugo Estrada wrote:
> > 1. What is the best practice with namespaces? Should I follow
> > java-style namespacing names, or does clojure has its own favored
> > style?
>
> Most packages simply have a prefix matching the name of the package,
> without domain.  This isn't universal, though.
>
> > 2. Is there a reference somewhere out there where I could consult these
> > kinds of questions?
>
> The best reference is existing project practice; there's a wealth of
> free software source code out there.
>
> --
> Stephen Compall
> ^aCollection allSatisfy: [:each|aCondition]: less is better
>
>

-- 
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: newbie question on namespaces and reference resources

2012-08-17 Thread Stephen Compall
On Sun, 2012-08-12 at 19:55 -0700, Hugo Estrada wrote:
> 1. What is the best practice with namespaces? Should I follow
> java-style namespacing names, or does clojure has its own favored
> style?

Most packages simply have a prefix matching the name of the package,
without domain.  This isn't universal, though.

> 2. Is there a reference somewhere out there where I could consult these 
> kinds of questions? 

The best reference is existing project practice; there's a wealth of
free software source code out there.

-- 
Stephen Compall
^aCollection allSatisfy: [:each|aCondition]: less is better

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


newbie question on namespaces and reference resources

2012-08-15 Thread Hugo Estrada
Hi, there,

I have a practical questioned followed by a general questions.

1. What is the best practice with namespaces? Should I follow java-style 
namespacing names, or does clojure has its own favored style?

2. Is there a reference somewhere out there where I could consult these 
kinds of questions? 

Thanks in advance,

Hugo

-- 
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: a newbie question

2012-07-06 Thread Like The Color
I am also a newbie at clojure and wanted to share that I have found the 
http://www.4clojure.com/ site to be helpful.  You are presented with a 
problem set for which you provide a solution.  If you get it wrong it tells 
you and you try again.  If you get it right you move on to another set. 
 They have a number of problems in different areas.

You can also see the solutions of others which I find helpful.

Best of luck,
Dan

On Wednesday, July 4, 2012 1:46:57 PM UTC-5, John Holland wrote:
>
> Thanks everybody
>
> On Wed, Jul 4, 2012 at 2:16 PM, Tassilo Horn wrote:
>
>> John Holland  writes:
>>
>> Hi John,
>>
>> > If I want to get the last n elements of a list or vector I am doing
>> > the following:
>> >
>> > (reverse (take n (reverse thelist)))
>> >
>> > Is there a better way to do this?
>>
>> For vectors, you can do that much more efficiently using subvec:
>>
>>   (subvec my-vec (- (count vec) n))
>>
>> For all sequential collections (lists, vectors, and sequences), I think
>> this should be better:
>>
>>   (drop (- (count my-seq) n) my-seq)
>>
>> That's because lists, vectors, seqs (with the exception of lazy seqs)
>> usually implement the Counted abstraction meaning that (count coll) is a
>> constant time operation.
>>
>> 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
>>
>
>
>
> -- 
>
> __
>
> Note new email address jbholl...@gmail.com
>

-- 
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: newbie question about the difference of proxy [Runnable] and fn

2012-07-06 Thread Moritz Ulrich
On Fri, Jul 6, 2012 at 5:22 PM, grahamke  wrote:
> (.start (Thread. (println "I ran!") "tName"))

You're missing a # here. You create a new thread object passing two
args to the Thread constructor: The return value of (println ...) and
"tName". println returns nil, so you effectively do (Thread. nil
"tName").

The difference in behavior is, that the first version runs the println
in the repl thread BEFORE spawning a new thread (which doesn't do
anything in this case).

You want to pass a Runnable object (e.g. a function) as the first
argument: (.start (Thread. #(println "Ohai!"), "tName")). This will
create a new thread which will run the supplied function which will
print a message to the console.


Background threads usually print to the console because *out* etc.
isn't redirected to the REPL.

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


newbie question about the difference of proxy [Runnable] and fn

2012-07-06 Thread grahamke
Hi,

I was experimenting with examples from Stu's Programming Clojure book and 
I'm puzzled why these two function behave differently when run in the repl:

(.start (Thread. (println "I ran!") "tName"))

(.start (Thread.
  (proxy [Runnable] [] (run [] (println "I ran!"))) "tName"))


The first function returns nil and prints I ran! to the repl window in 
eclipse.

The second function doesn't return anything and prints I ran! to the 
console.


What is it about proxy that changes the behavior?  When I use proxy does 
the Java "takeover" and ignore the repl?

Thanks,
grahamke

-- 
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: a newbie question

2012-07-04 Thread Michał Marczyk
Note that subvec as currently implemented does not return a first
class vector; it prevents the original vector from being garbage
collected, because it delegates all basic operations to it, and it
does not support some less-basic operations (you cannot make a
transient out of a subvec-created vector). It is the fastest possible
way of obtaining a view on a fragment of a vector, though.

Also note that vectors support rseq ("seq in reverse" produced in
constant time), so you could always

(reverse (take n (rseq v)))

Cheers,
Michał


On 4 July 2012 21:01, Jay Fields  wrote:
> I think subvec is likely what you're looking for, but I also wanted to
> mention take-last for the sake of completeness.
>
> On Wed, Jul 4, 2012 at 2:16 PM, Tassilo Horn  wrote:
>> John Holland  writes:
>>
>> Hi John,
>>
>>> If I want to get the last n elements of a list or vector I am doing
>>> the following:
>>>
>>> (reverse (take n (reverse thelist)))
>>>
>>> Is there a better way to do this?
>>
>> For vectors, you can do that much more efficiently using subvec:
>>
>>   (subvec my-vec (- (count vec) n))
>>
>> For all sequential collections (lists, vectors, and sequences), I think
>> this should be better:
>>
>>   (drop (- (count my-seq) n) my-seq)
>>
>> That's because lists, vectors, seqs (with the exception of lazy seqs)
>> usually implement the Counted abstraction meaning that (count coll) is a
>> constant time operation.
>>
>> 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
>
> --
> 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: a newbie question

2012-07-04 Thread Jay Fields
I think subvec is likely what you're looking for, but I also wanted to
mention take-last for the sake of completeness.

On Wed, Jul 4, 2012 at 2:16 PM, Tassilo Horn  wrote:
> John Holland  writes:
>
> Hi John,
>
>> If I want to get the last n elements of a list or vector I am doing
>> the following:
>>
>> (reverse (take n (reverse thelist)))
>>
>> Is there a better way to do this?
>
> For vectors, you can do that much more efficiently using subvec:
>
>   (subvec my-vec (- (count vec) n))
>
> For all sequential collections (lists, vectors, and sequences), I think
> this should be better:
>
>   (drop (- (count my-seq) n) my-seq)
>
> That's because lists, vectors, seqs (with the exception of lazy seqs)
> usually implement the Counted abstraction meaning that (count coll) is a
> constant time operation.
>
> 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

-- 
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: a newbie question

2012-07-04 Thread John Holland
Thanks everybody

On Wed, Jul 4, 2012 at 2:16 PM, Tassilo Horn  wrote:

> John Holland  writes:
>
> Hi John,
>
> > If I want to get the last n elements of a list or vector I am doing
> > the following:
> >
> > (reverse (take n (reverse thelist)))
> >
> > Is there a better way to do this?
>
> For vectors, you can do that much more efficiently using subvec:
>
>   (subvec my-vec (- (count vec) n))
>
> For all sequential collections (lists, vectors, and sequences), I think
> this should be better:
>
>   (drop (- (count my-seq) n) my-seq)
>
> That's because lists, vectors, seqs (with the exception of lazy seqs)
> usually implement the Counted abstraction meaning that (count coll) is a
> constant time operation.
>
> 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
>



-- 

__

Note new email address jbholl...@gmail.com

-- 
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: a newbie question

2012-07-04 Thread Tassilo Horn
John Holland  writes:

Hi John,

> If I want to get the last n elements of a list or vector I am doing
> the following:
>
> (reverse (take n (reverse thelist)))
>
> Is there a better way to do this?

For vectors, you can do that much more efficiently using subvec:

  (subvec my-vec (- (count vec) n))

For all sequential collections (lists, vectors, and sequences), I think
this should be better:

  (drop (- (count my-seq) n) my-seq)

That's because lists, vectors, seqs (with the exception of lazy seqs)
usually implement the Counted abstraction meaning that (count coll) is a
constant time operation.

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


Re: a newbie question

2012-07-04 Thread Timothy Baldridge
> Is there a better way to do this?

Use subvec for vectors. For lists, look at take and but-last.

Timothy

-- 
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: a newbie question

2012-07-04 Thread Steven E. Harris
John Holland  writes:

> Is there a better way to do this?

See `take-last'¹ and, specifically for vectors where you can calculate
the start index of the suffix, `subvec'².

Note that even though Clojure has a `last' function with the same name
as Common Lisp's `last'³, the former lacks the optional count argument
accepted by the latter.


Footnotes: 
¹ http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/take-last
² http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/subvec
³ http://www.lispworks.com/documentation/HyperSpec/Body/f_last.htm

-- 
Steven E. Harris

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


a newbie question

2012-07-04 Thread John Holland
If I want to get the last n elements of a list or vector I am doing the
following:

(reverse (take n (reverse thelist)))


Is there a better way to do this?

I'm going through some basic coding exercises which were meant for Java but
I'm finding them educational to get started with Clojure.

-- 
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: Newbie question about rebinding local variables

2012-04-22 Thread Tim Cross


On Saturday, April 21, 2012 12:26:30 AM UTC+10, Craig Ching wrote:
>
>
>
> On Friday, April 20, 2012 9:07:49 AM UTC-5, Walter van der Laan wrote:
>>
>> You could start with pure functions to handle the game logic, e.g.:
>>
>> (defn new-game []
>>   [[\- \- \-]
>>[\- \- \-]
>>[\- \- \-]])
>>
>> (defn print-game [game]
>>   (doseq [row game]
>> (println (apply str row
>>
>> (defn move [game mark pos]
>>   (assoc-in game pos mark))
>>
>> (print-game (new-game))
>> (print-game (move (new-game) \x [1 1]))
>> (print-game (-> (new-game) (move \x [1 1]) (move \o [0 2])))
>>
>
>
> Right, but then I'm having to keep track of the moves and reapply them on 
> every game update, right?  I guess my question is more conceptual (so that 
> I can gain an understanding of Clojure), I don't really care about tic tac 
> toe, what I really care about is how to maintain mutable state.
>
>
Yes, you will need to track the state, but keep in mind that Clojure is 
clever about copies and works to make sure they are very fast and use as 
few resources as possible. I would be careful of thinking of the changes in 
state as being mutable state rather than new state simply because of old 
habits where copying of state was an expensive operation. I think the 
functional approach is the way to go. Highly recommend reading some of 
Rich's articles on state at the clojure site. 

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: Newbie question about rebinding local variables

2012-04-22 Thread Tim Cross


On Friday, April 20, 2012 8:21:56 AM UTC+10, Craig Ching wrote:
>
> Ok, I've read that what I want to do is a no no.  But this is the sort of 
> thing I did in Scheme about 20 years ago (and because of that I'm probably 
> misremembering ;-)).
>
> Basically I'm learning clojure and thought I'd write a tic tac toe game. 
>  But not any tic tac toe, I want to write one where I can have multiple 
> games going simultaneously.  Something like:
>
> (def g1 (new-game))
> (def g2 (new-game))
>
> (g1 :x 0)
> (g1 :print)
> (g2 :x 5)
> (g2 :print)
>
> So the schemer in me (and probably the imperative programmer as well) 
> thought I could return a clojure that encapsulates the board value, 
> something like this:
>
> (defn new-game []
>
>   (let [board (into [] (repeat 9 nil))]
>
> (fn [n i]
>
>   (cond
>
> (= n :x)(set! board (assoc board i 'x))
>
> (= n :o)(set! board (assoc board i 'o))
>
> (= n :print) (println board)
>
> Of course I get an error saying I can't bind to the non-mutable board.
>
> I'm really new to Clojure, so apologies if this is really basic for this 
> list.  Can I do what I want or can someone point me in the right direction? 
>  I've seen some other tic tac toe implementations on github, but they use 
> recur to track state and I was hoping there was a cleaner idiomatic way 
> than that.
>
> Thanks!
>
>

-- 
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: Newbie question about rebinding local variables

2012-04-21 Thread Alex Baranosky
Another non-standard solution you could try is to use the state monad from
the monad library.
On Apr 21, 2012 3:22 PM, "Sergey Didenko"  wrote:

> There is also a non-idiomatic way - transform your code to use a
> native Java data structure like ArrayList or primitive array.
>
> You may want it for the speed or if the mutable algorithm is more
> readable. Anyway isolation of the mutable code is always a good
> advice.
>
> (defn new-game []
>
>  (let [board (java.util.ArrayList. (repeat 9 nil))]
>
>(fn [n i]
>
>  (cond
>
>(= n :x)(.set board i 'x)
>
>(= n :o)(.set board i 'o)
>
>(= n :print) (println board)
>
> --
> 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: Newbie question about rebinding local variables

2012-04-21 Thread Sergey Didenko
There is also a non-idiomatic way - transform your code to use a
native Java data structure like ArrayList or primitive array.

You may want it for the speed or if the mutable algorithm is more
readable. Anyway isolation of the mutable code is always a good
advice.

(defn new-game []

  (let [board (java.util.ArrayList. (repeat 9 nil))]

(fn [n i]

  (cond

(= n :x)(.set board i 'x)

(= n :o)(.set board i 'o)

(= n :print) (println board)

-- 
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: Newbie question about rebinding local variables

2012-04-20 Thread Craig Ching


On Friday, April 20, 2012 1:15:11 PM UTC-5, kurtharriger wrote:
>
>
> Game state does not have to be a map, it could be any datastructure 
> you want, perhaps a protocol that is implemented by a concrete class 
> in another JVM language.  However, I avoid encapsulation unless there 
> is a compelling reason reason to add it.  More often then not the 
> result of encapsulation is that the entire library of useful functions 
> like map, reduce, get-in, update-in, etc... are no longer useable with 
> this custom data structure. 
>
> It is also not strictly required that all your functions be pure, you 
> could load or save game state to a database or external service as 
> necessary. There are very few applications that are strictly pure. 
> However, it is recommended that you make as much of your program pure 
> as possible.  If each time you made a game move the state was written 
> to a database then you might have difficulty trying to run multiple 
> solver strategies in parallel as these side-effects would continuously 
> clobber the others database state. 
>
> The general idea is that pure functions are easily composed and easy 
> to test, so use them whenever possible.  Impure functions that write 
> to external services are often much more difficult to compose and 
> test, so keep them as small as possible. Think twice about calling an 
> impure function from a pure function as this makes it impure... main 
> will almost certainly be impure, but that does not mean that 
> everything else also needs to be impure. 
>

I think that gives me a lot to ruminate on.  Thanks, I appreciate the 
detailed advice. 

-- 
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: Newbie question about rebinding local variables

2012-04-20 Thread kurtharriger


On Apr 20, 9:43 am, Craig Ching  wrote:
> Thanks for your input, I appreciate it.
>
> On Friday, April 20, 2012 10:16:51 AM UTC-5, kurtharriger wrote:
>
> > And you just need to keep the resulting state, no need to reapply the
> > moves.
> > Your main method might use a reduce or loop recur.
>
> > (loop [game (new-game)]
> >   (if-not (complete? game)
> >     (recur (make-random-move game)))
>
> The problem I have with this is that it does encapsulate game state
> completely, including input (the moves), but I want to just encapsulate
> board state.  Imagine that the moves come from an external source, i.e. the
> web, my game state can't be stuck down in a function somewhere, the move is
> sent from the web, the game state is retrieved from somewhere (a session?
>  a database?), and updated with the incoming move.  I wasn't clear in
> stating my problem, but I want to decouple game state and board state for
> this reason.  And because that's where I'm headed, it might make sense for
> me to approach this using atoms as others have suggested.
>
> I appreciate the different perspectives though, it's helping me understand!

Game state does not have to be a map, it could be any datastructure
you want, perhaps a protocol that is implemented by a concrete class
in another JVM language.  However, I avoid encapsulation unless there
is a compelling reason reason to add it.  More often then not the
result of encapsulation is that the entire library of useful functions
like map, reduce, get-in, update-in, etc... are no longer useable with
this custom data structure.

It is also not strictly required that all your functions be pure, you
could load or save game state to a database or external service as
necessary. There are very few applications that are strictly pure.
However, it is recommended that you make as much of your program pure
as possible.  If each time you made a game move the state was written
to a database then you might have difficulty trying to run multiple
solver strategies in parallel as these side-effects would continuously
clobber the others database state.

The general idea is that pure functions are easily composed and easy
to test, so use them whenever possible.  Impure functions that write
to external services are often much more difficult to compose and
test, so keep them as small as possible. Think twice about calling an
impure function from a pure function as this makes it impure... main
will almost certainly be impure, but that does not mean that
everything else also needs to be impure.

-- 
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: Newbie question about rebinding local variables

2012-04-20 Thread nicolas.o...@gmail.com
This is not the idiomatic way but you can stay quite close from your code by:

(defn game [ board ]
 (fn [n i]
  (cond
 (= n :x) (game (assoc board i 'x))
 ( = n :o) (game (assoc board i 'o))
 (= n :print) (println board

(defn (new-game (game (into [] (repeat 9 nil)

But this is still an encoding of message-passing OO, which is not very
idiomatic.

-- 
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: Newbie question about rebinding local variables

2012-04-20 Thread Walter van der Laan
You can save state in an atom like this:
(def state (atom (new-game))) ; initial state
(swap! state move \x [1 1]) ; make a move

-- 
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: Newbie question about rebinding local variables

2012-04-20 Thread Phil Hagelberg
On Fri, Apr 20, 2012 at 7:07 AM, Walter van der Laan
 wrote:
> You could start with pure functions to handle the game logic, e.g.:

We did this during swarm coding at ClojureWest on the game of Go, but
you could apply the same logic to any board game:

https://github.com/technomancy/swarm-go/blob/master/src/swarm/go.clj
(ignore the atom at the top; it's not used)

Basically it's implemented in terms of reduce where the accumulator is
the board state and the sequence is the list of moves. You can use the
reductions function to get access to each intermediate state lazily.

-Phil

-- 
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: Newbie question about rebinding local variables

2012-04-20 Thread Craig Ching
Thanks for your input, I appreciate it.

On Friday, April 20, 2012 10:16:51 AM UTC-5, kurtharriger wrote:
>
> And you just need to keep the resulting state, no need to reapply the 
> moves.  
> Your main method might use a reduce or loop recur.
>
> (loop [game (new-game)]
>   (if-not (complete? game) 
> (recur (make-random-move game)))
>

The problem I have with this is that it does encapsulate game state 
completely, including input (the moves), but I want to just encapsulate 
board state.  Imagine that the moves come from an external source, i.e. the 
web, my game state can't be stuck down in a function somewhere, the move is 
sent from the web, the game state is retrieved from somewhere (a session? 
 a database?), and updated with the incoming move.  I wasn't clear in 
stating my problem, but I want to decouple game state and board state for 
this reason.  And because that's where I'm headed, it might make sense for 
me to approach this using atoms as others have suggested.

I appreciate the different perspectives though, it's helping me understand! 

-- 
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: Newbie question about rebinding local variables

2012-04-20 Thread kurtharriger
And you just need to keep the resulting state, no need to reapply the moves.  
Your main method might use a reduce or loop recur.

(loop [game (new-game)]
  (if-not (complete? game) 
(recur (make-random-move game)))

-- 
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: Newbie question about rebinding local variables

2012-04-20 Thread kurtharriger
By creating new game objects rather than mutating existing ones you could do 
things you wouldnt otherwise be able to do. Perhaps you have different solver 
strategies that you want to apply in parallel. Provided you can give each 
solver its own copy this is trivial, but if your datastructures require 
mutation this gets messy fast.  
When passing objects as parameters dependencies are more explicit, you can of 
course group related objects together and pass them as a single parameter and 
what not.. destructuring as needed.  In practice its not as bad as it seems. 
For values like configuration settings that are not usually changed you might 
consider dynamic vars to reduce number of parameters. 

-- 
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: Newbie question about rebinding local variables

2012-04-20 Thread Craig Ching


On Friday, April 20, 2012 9:07:49 AM UTC-5, Walter van der Laan wrote:
>
> You could start with pure functions to handle the game logic, e.g.:
>
> (defn new-game []
>   [[\- \- \-]
>[\- \- \-]
>[\- \- \-]])
>
> (defn print-game [game]
>   (doseq [row game]
> (println (apply str row
>
> (defn move [game mark pos]
>   (assoc-in game pos mark))
>
> (print-game (new-game))
> (print-game (move (new-game) \x [1 1]))
> (print-game (-> (new-game) (move \x [1 1]) (move \o [0 2])))
>


Right, but then I'm having to keep track of the moves and reapply them on 
every game update, right?  I guess my question is more conceptual (so that 
I can gain an understanding of Clojure), I don't really care about tic tac 
toe, what I really care about is how to maintain mutable state.

>

-- 
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: Newbie question about rebinding local variables

2012-04-20 Thread Walter van der Laan
You could start with pure functions to handle the game logic, e.g.:

(defn new-game []
  [[\- \- \-]
   [\- \- \-]
   [\- \- \-]])

(defn print-game [game]
  (doseq [row game]
(println (apply str row

(defn move [game mark pos]
  (assoc-in game pos mark))

(print-game (new-game))
(print-game (move (new-game) \x [1 1]))
(print-game (-> (new-game) (move \x [1 1]) (move \o [0 2])))

On Friday, April 20, 2012 3:30:59 PM UTC+2, Craig Ching wrote:
>
> Thanks for the help to both of you!  Question, does it seem heavy handed 
> to do it this way?  I mean, atoms are more for thread-safety, aren't they? 
>  I don't have threads so it seems a bit much to use atoms for this.  Am I 
> better off using recur and trying to loop?  Or is this considered an 
> idiomatic way to handle mutable data in Clojure?  I always found wrapping 
> up mutable data in a closure as we did in Scheme to be pretty elegant, but 
> maybe something like that goes against the desire of Clojure to protect 
> against concurrent modification, is that about right?
>
> Thanks again!
>
> On Thursday, April 19, 2012 10:01:23 PM UTC-5, Gaz wrote:
>>
>> to answer your question directly, you would need to do something like
>> this to make it work the way your example is set up:
>>
>> (defn new-game []
>>   (let [board (atom (into [] (repeat 9 nil)))]
>> (fn [n & [i]]
>>   (cond
>>(= n :x) (swap! board assoc i 'x)
>>(= n :o) (swap! board assoc i 'o)
>>(= n :print) (println @board)
>>
>> (def g1 (new-game))
>>
>> (g1 :x 0)
>> (g1 :print)
>>
>> On Thu, Apr 19, 2012 at 9:58 PM, Armando Blancas  
>> wrote:
>> > You could keep the board in an atom so it can mutate; then try to find 
>> maybe
>> > two good places for mutation to happen, your move and the program's. 
>> With
>> > the rest being functional you'll avoid the problems of global state 
>> while
>> > not being forced to fit your logic into a loop of some re-binding that
>> > simulates mutation.
>> >
>> >
>> > On Thursday, April 19, 2012 3:21:56 PM UTC-7, Craig Ching wrote:
>> >>
>> >> Ok, I've read that what I want to do is a no no.  But this is the sort 
>> of
>> >> thing I did in Scheme about 20 years ago (and because of that I'm 
>> probably
>> >> misremembering ;-)).
>> >>
>> >> Basically I'm learning clojure and thought I'd write a tic tac toe 
>> game.
>> >>  But not any tic tac toe, I want to write one where I can have multiple
>> >> games going simultaneously.  Something like:
>> >>
>> >> (def g1 (new-game))
>> >> (def g2 (new-game))
>> >>
>> >> (g1 :x 0)
>> >> (g1 :print)
>> >> (g2 :x 5)
>> >> (g2 :print)
>> >>
>> >> So the schemer in me (and probably the imperative programmer as well)
>> >> thought I could return a clojure that encapsulates the board value,
>> >> something like this:
>> >>
>> >> (defn new-game []
>> >>
>> >>   (let [board (into [] (repeat 9 nil))]
>> >>
>> >> (fn [n i]
>> >>
>> >>   (cond
>> >>
>> >> (= n :x)(set! board (assoc board i 'x))
>> >>
>> >> (= n :o)(set! board (assoc board i 'o))
>> >>
>> >> (= n :print) (println board)
>> >>
>> >>
>> >> Of course I get an error saying I can't bind to the non-mutable board.
>> >>
>> >> I'm really new to Clojure, so apologies if this is really basic for 
>> this
>> >> list.  Can I do what I want or can someone point me in the right 
>> direction?
>> >>  I've seen some other tic tac toe implementations on github, but they 
>> use
>> >> recur to track state and I was hoping there was a cleaner idiomatic 
>> way than
>> >> that.
>> >>
>> >> Thanks!
>> >>
>> > --
>> > 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: Newbie question about rebinding local variables

2012-04-20 Thread Craig Ching
Thanks for the help to both of you!  Question, does it seem heavy handed to 
do it this way?  I mean, atoms are more for thread-safety, aren't they?  I 
don't have threads so it seems a bit much to use atoms for this.  Am I 
better off using recur and trying to loop?  Or is this considered an 
idiomatic way to handle mutable data in Clojure?  I always found wrapping 
up mutable data in a closure as we did in Scheme to be pretty elegant, but 
maybe something like that goes against the desire of Clojure to protect 
against concurrent modification, is that about right?

Thanks again!

On Thursday, April 19, 2012 10:01:23 PM UTC-5, Gaz wrote:
>
> to answer your question directly, you would need to do something like
> this to make it work the way your example is set up:
>
> (defn new-game []
>   (let [board (atom (into [] (repeat 9 nil)))]
> (fn [n & [i]]
>   (cond
>(= n :x) (swap! board assoc i 'x)
>(= n :o) (swap! board assoc i 'o)
>(= n :print) (println @board)
>
> (def g1 (new-game))
>
> (g1 :x 0)
> (g1 :print)
>
> On Thu, Apr 19, 2012 at 9:58 PM, Armando Blancas  
> wrote:
> > You could keep the board in an atom so it can mutate; then try to find 
> maybe
> > two good places for mutation to happen, your move and the program's. With
> > the rest being functional you'll avoid the problems of global state while
> > not being forced to fit your logic into a loop of some re-binding that
> > simulates mutation.
> >
> >
> > On Thursday, April 19, 2012 3:21:56 PM UTC-7, Craig Ching wrote:
> >>
> >> Ok, I've read that what I want to do is a no no.  But this is the sort 
> of
> >> thing I did in Scheme about 20 years ago (and because of that I'm 
> probably
> >> misremembering ;-)).
> >>
> >> Basically I'm learning clojure and thought I'd write a tic tac toe game.
> >>  But not any tic tac toe, I want to write one where I can have multiple
> >> games going simultaneously.  Something like:
> >>
> >> (def g1 (new-game))
> >> (def g2 (new-game))
> >>
> >> (g1 :x 0)
> >> (g1 :print)
> >> (g2 :x 5)
> >> (g2 :print)
> >>
> >> So the schemer in me (and probably the imperative programmer as well)
> >> thought I could return a clojure that encapsulates the board value,
> >> something like this:
> >>
> >> (defn new-game []
> >>
> >>   (let [board (into [] (repeat 9 nil))]
> >>
> >> (fn [n i]
> >>
> >>   (cond
> >>
> >> (= n :x)(set! board (assoc board i 'x))
> >>
> >> (= n :o)(set! board (assoc board i 'o))
> >>
> >> (= n :print) (println board)
> >>
> >>
> >> Of course I get an error saying I can't bind to the non-mutable board.
> >>
> >> I'm really new to Clojure, so apologies if this is really basic for this
> >> list.  Can I do what I want or can someone point me in the right 
> direction?
> >>  I've seen some other tic tac toe implementations on github, but they 
> use
> >> recur to track state and I was hoping there was a cleaner idiomatic way 
> than
> >> that.
> >>
> >> Thanks!
> >>
> > --
> > 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: Newbie question about rebinding local variables

2012-04-19 Thread gaz jones
to answer your question directly, you would need to do something like
this to make it work the way your example is set up:

(defn new-game []
  (let [board (atom (into [] (repeat 9 nil)))]
(fn [n & [i]]
  (cond
   (= n :x) (swap! board assoc i 'x)
   (= n :o) (swap! board assoc i 'o)
   (= n :print) (println @board)

(def g1 (new-game))

(g1 :x 0)
(g1 :print)

On Thu, Apr 19, 2012 at 9:58 PM, Armando Blancas  wrote:
> You could keep the board in an atom so it can mutate; then try to find maybe
> two good places for mutation to happen, your move and the program's. With
> the rest being functional you'll avoid the problems of global state while
> not being forced to fit your logic into a loop of some re-binding that
> simulates mutation.
>
>
> On Thursday, April 19, 2012 3:21:56 PM UTC-7, Craig Ching wrote:
>>
>> Ok, I've read that what I want to do is a no no.  But this is the sort of
>> thing I did in Scheme about 20 years ago (and because of that I'm probably
>> misremembering ;-)).
>>
>> Basically I'm learning clojure and thought I'd write a tic tac toe game.
>>  But not any tic tac toe, I want to write one where I can have multiple
>> games going simultaneously.  Something like:
>>
>> (def g1 (new-game))
>> (def g2 (new-game))
>>
>> (g1 :x 0)
>> (g1 :print)
>> (g2 :x 5)
>> (g2 :print)
>>
>> So the schemer in me (and probably the imperative programmer as well)
>> thought I could return a clojure that encapsulates the board value,
>> something like this:
>>
>> (defn new-game []
>>
>>   (let [board (into [] (repeat 9 nil))]
>>
>>     (fn [n i]
>>
>>       (cond
>>
>>         (= n :x)(set! board (assoc board i 'x))
>>
>>         (= n :o)(set! board (assoc board i 'o))
>>
>>         (= n :print) (println board)
>>
>>
>> Of course I get an error saying I can't bind to the non-mutable board.
>>
>> I'm really new to Clojure, so apologies if this is really basic for this
>> list.  Can I do what I want or can someone point me in the right direction?
>>  I've seen some other tic tac toe implementations on github, but they use
>> recur to track state and I was hoping there was a cleaner idiomatic way than
>> that.
>>
>> Thanks!
>>
> --
> 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: Newbie question about rebinding local variables

2012-04-19 Thread Armando Blancas
You could keep the board in an atom so it can mutate; then try to find 
maybe two good places for mutation to happen, your move and the program's. 
With the rest being functional you'll avoid the problems of global state 
while not being forced to fit your logic into a loop of some re-binding 
that simulates mutation.

On Thursday, April 19, 2012 3:21:56 PM UTC-7, Craig Ching wrote:
>
> Ok, I've read that what I want to do is a no no.  But this is the sort of 
> thing I did in Scheme about 20 years ago (and because of that I'm probably 
> misremembering ;-)).
>
> Basically I'm learning clojure and thought I'd write a tic tac toe game. 
>  But not any tic tac toe, I want to write one where I can have multiple 
> games going simultaneously.  Something like:
>
> (def g1 (new-game))
> (def g2 (new-game))
>
> (g1 :x 0)
> (g1 :print)
> (g2 :x 5)
> (g2 :print)
>
> So the schemer in me (and probably the imperative programmer as well) 
> thought I could return a clojure that encapsulates the board value, 
> something like this:
>
> (defn new-game []
>
>   (let [board (into [] (repeat 9 nil))]
>
> (fn [n i]
>
>   (cond
>
> (= n :x)(set! board (assoc board i 'x))
>
> (= n :o)(set! board (assoc board i 'o))
>
> (= n :print) (println board)
>
> Of course I get an error saying I can't bind to the non-mutable board.
>
> I'm really new to Clojure, so apologies if this is really basic for this 
> list.  Can I do what I want or can someone point me in the right direction? 
>  I've seen some other tic tac toe implementations on github, but they use 
> recur to track state and I was hoping there was a cleaner idiomatic way 
> than that.
>
> Thanks!
>
>

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

Newbie question about rebinding local variables

2012-04-19 Thread Craig Ching
Ok, I've read that what I want to do is a no no.  But this is the sort of 
thing I did in Scheme about 20 years ago (and because of that I'm probably 
misremembering ;-)).

Basically I'm learning clojure and thought I'd write a tic tac toe game. 
 But not any tic tac toe, I want to write one where I can have multiple 
games going simultaneously.  Something like:

(def g1 (new-game))
(def g2 (new-game))

(g1 :x 0)
(g1 :print)
(g2 :x 5)
(g2 :print)

So the schemer in me (and probably the imperative programmer as well) 
thought I could return a clojure that encapsulates the board value, 
something like this:

(defn new-game []

  (let [board (into [] (repeat 9 nil))]

(fn [n i]

  (cond

(= n :x)(set! board (assoc board i 'x))

(= n :o)(set! board (assoc board i 'o))

(= n :print) (println board)

Of course I get an error saying I can't bind to the non-mutable board.

I'm really new to Clojure, so apologies if this is really basic for this 
list.  Can I do what I want or can someone point me in the right direction? 
 I've seen some other tic tac toe implementations on github, but they use 
recur to track state and I was hoping there was a cleaner idiomatic way 
than that.

Thanks!

-- 
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: Sorry Don't understand "for macro", a bug or a newbie-question??

2012-01-20 Thread aschoerk
Ah,
thank you,  so a newbie question.
But helped me a lot.

Andreas

On Jan 18, 10:26 pm, Jack Moffitt  wrote:
> > doesn't show any effect of the for.
> > The only difference is the additional statement at the end.
> > I can not imagine how this statement sequentially behind can influence
> > the for.
>
> for returns a lazy sequence. In the first case, in printing out the
> result to the REPL, the lazy sequence is realized, and in the second,
> the result is discarded so it is never realized.
>
> jack.

-- 
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: Sorry Don't understand "for macro", a bug or a newbie-question??

2012-01-18 Thread dennis zhuang
for returns a lazy sequence.You may prefer doseq:
(defn fortest2 []
 (doseq [a (range 2 10)
 b (range 2 10)]
   (do
 (println "x: " a " b:" b)
 (list a b)))
 (println "ende")
 )
(fortest2)

doseq will be forced for side-effects.

2012/1/19 Jack Moffitt 

> > doesn't show any effect of the for.
> > The only difference is the additional statement at the end.
> > I can not imagine how this statement sequentially behind can influence
> > the for.
>
> for returns a lazy sequence. In the first case, in printing out the
> result to the REPL, the lazy sequence is realized, and in the second,
> the result is discarded so it is never realized.
>
> jack.
>
> --
> 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
>



-- 
庄晓丹
Email:killme2...@gmail.com
伯岩(花名)  bo...@taobao.com
Site:   http://fnil.net

淘宝(中国)软件有限公司 / 产品技术部 / Java中间件

-- 
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: Sorry Don't understand "for macro", a bug or a newbie-question??

2012-01-18 Thread Jack Moffitt
> doesn't show any effect of the for.
> The only difference is the additional statement at the end.
> I can not imagine how this statement sequentially behind can influence
> the for.

for returns a lazy sequence. In the first case, in printing out the
result to the REPL, the lazy sequence is realized, and in the second,
the result is discarded so it is never realized.

jack.

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


Sorry Don't understand "for macro", a bug or a newbie-question??

2012-01-18 Thread aschoerk
Hello,

I am quite puzzled:

(defn fortest1 []
  (for [a (range 2 10)
  b (range 2 10)]
(do
  (println "x: " a " b:" b)
  (list a b)))
  )

(fortest1)

Shows the running "for macro"

(defn fortest2 []
  (for [a (range 2 10)
  b (range 2 10)]
(do
  (println "x: " a " b:" b)
  (list a b)))
  (println "ende")
  )
(fortest2)

doesn't show any effect of the for.
The only difference is the additional statement at the end.
I can not imagine how this statement sequentially behind can influence
the for.

Hope anybody can help

I am testing using 1.2.0 and 1.4.0-master and ccw inside eclipse

Andreas

-- 
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: Another newbie question

2011-11-08 Thread Sean Corfield
On Tue, Nov 8, 2011 at 4:09 PM, pron  wrote:
> Yes, but it lacks cross-referencing and linking from within the docstrings
> themselves (like Javadoc's @See).

You can use :see-also metadata to cause autodoc to generate
cross-references with links... I think it would be pretty easy to
extend autodoc to do more of what you're looking for (but I think it's
already closer than you might believe :)

> BTW, I'd like to say that your "Real World Clojure" series has been
> extremely helpful. Thank you for that. I wish someone would write a similar
> series about the less technological aspects. Something along the lines of
> Alex Miller's excellent post - we could use more of that!

Yup, I plan to write more in that series!
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.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: Another newbie question

2011-11-08 Thread pron


On Tuesday, November 8, 2011 8:42:13 PM UTC+2, Sean Corfield wrote:
>
> Have you looked at autodoc? 
>

Yes, but it lacks cross-referencing and linking from within the docstrings 
themselves (like Javadoc's @See). I would like to suggest tagging in order 
to compensate for the lack of  Javadoc's "Use" page (that is possible due 
to static typing) - something that will allow grouping functions according 
to concepts and/or data structures in addition to grouping by namespace.

BTW, I'd like to say that your "Real World Clojure" series has been 
extremely helpful. Thank you for that. I wish someone would write a similar 
series about the less technological aspects. Something along the lines of 
Alex Miller's excellent 
post - 
we could use more of that!

-- 
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: Another newbie question

2011-11-08 Thread Sean Corfield
On Tue, Nov 8, 2011 at 3:14 AM, pron  wrote:
> Yeah, sure, but docstrings aren't linkable. It's interesting that Java, with
> all its faults, has an incredible documentation system.

Have you looked at autodoc? It's responsible for generating stuff like this:

http://clojure.github.com/java.jdbc/

Direct links to source code, table of contents containing links to all
the functions...

> Well, that in itself is reassuring.  Can anyone share the size of the team
> involved? The duration of the project?

I'll leave that to others. World Singles has a small team. The project
is ongoing. I started working with Clojure in early 2010 and
introduced it at work probably about a year ago as an option for our
JVM-based mixed-language codebase. Our first Clojure code went to
production in June or July and we're very happy with how things are
going.

> some, like Clojure, are
> more novel (if not in their language concepts, then in their commercial
> applications).

A lot of working production software has been built with Lisps over
the years (but I understand your concerns about the "novelty" of
Clojure, in terms of age). The list of Clojure "success stories" has a
broad range of companies but I'll concede a lot of them are
startup-style organizations who are a lot less risk-averse than many
corporations:

http://dev.clojure.org/display/community/Clojure+Success+Stories
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.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


  1   2   3   4   5   >