Re: Best practices for named arguments

2012-06-15 Thread Vinzent

>
> TL;DR: I want to know best practices for designing functions with multiple 
> optional arguments.
>

Use destructing:

(defn f [required & {:keys [foo bar] :or {foo :default}}]
  [required foo bar])

(f 3 :bar 1 :foo 2) ;=> [3 2 1]
(f 3 :bar 1)  ;=> [3 :default 1]

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

Re: Best practices for named arguments

2012-06-15 Thread Meikel Brandmeyer (kotarak)
Hi,

you can use destructuring to provide defaults. And you can easily curry in 
options when passing things through.

(defn general-descend
  [xy ys &
   {:keys [gradient-fn cost-fn yield-fn alpha iterations thetas]
:or   {cost-fncost
   yield-fn   println
   alpha  0.01
   iterations 1000
   thetas (matrix 0 (second (dim xs)) 1)}}]
  ...)

(defn special-descend
  [xs ys & options]
  (apply general-descend xs ys :cost-fn cost options))

Kind regards
Meikel

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

Re: Best practices for named arguments

2012-06-15 Thread David Jacobs
I'm not sure you read the whole question. I want to know how to delegate 
optional arguments to other functions with the same method signatures.

On Friday, June 15, 2012 12:04:00 AM UTC-7, Vinzent wrote:
>
> TL;DR: I want to know best practices for designing functions with multiple 
>> optional arguments.
>>
>
> Use destructing:
>
> (defn f [required & {:keys [foo bar] :or {foo :default}}]
>   [required foo bar])
>
> (f 3 :bar 1 :foo 2) ;=> [3 2 1]
> (f 3 :bar 1)  ;=> [3 :default 1]
>

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

Re: Best practices for named arguments

2012-06-15 Thread David Jacobs
Ah I see, I didn't realize I could apply the general-descend algorithm to 
both atoms and arrays to get a flattened list. Thanks!

On Friday, June 15, 2012 12:05:36 AM UTC-7, Meikel Brandmeyer (kotarak) 
wrote:
>
> Hi,
>
> you can use destructuring to provide defaults. And you can easily curry in 
> options when passing things through.
>
> (defn general-descend
>   [xy ys &
>{:keys [gradient-fn cost-fn yield-fn alpha iterations thetas]
> :or   {cost-fncost
>yield-fn   println
>alpha  0.01
>iterations 1000
>thetas (matrix 0 (second (dim xs)) 1)}}]
>   ...)
>
> (defn special-descend
>   [xs ys & options]
>   (apply general-descend xs ys :cost-fn cost options))
>
> Kind regards
> Meikel
>
>

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

Re: ANN: lambic v. 0.1.0

2012-06-15 Thread Vinzent
Seems very interesting!

-- 
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: Clojurescript (latest) advanced mode compilation => java.lang.ClassCastException ?

2012-06-15 Thread Dave Sann
compiled, no problem

nice work, and thanks

D


On Friday, 15 June 2012 10:01:38 UTC+10, David Nolen wrote:
>
> This should be resolved in master - please let us know if you continue to 
> run into problems.
>
> On Thu, Jun 14, 2012 at 3:06 PM, David Nolen wrote:
>
>> Thank you! http://dev.clojure.org/jira/browse/CLJS-315
>>
>>
>> On Thu, Jun 14, 2012 at 6:43 AM, Dave Sann  wrote:
>>
>>> I (think) I have tracked it down to the following section of code from 
>>> jayq.core (simplified)
>>>
>>> ---
>>>
>>> (ns jayq.core)
>>>
>>> (extend-type js/jQuery
>>>   IIndexed
>>>   (-nth [this n]
>>> (when (< n (count this))
>>>   (.slice this n (inc n
>>>   (-nth [this n not-found]
>>> (if (< n (count this))
>>>   (.slice this n (inc n))
>>>   (if (undefined? not-found)
>>> nil
>>> not-found)))
>>>
>>>   ILookup
>>>   (-lookup
>>> ([this k]
>>>(or (.slice this k (inc k)) nil))
>>> ([this k not-found]
>>>(-nth this k not-found) ; < here if I 
>>> comment and replace with 1 this will compile in advanced mode.
>>>;1
>>>))
>>>   )
>>>
>>> ---
>>>
>>> if I compile this in simple mode - it is ok.
>>> In advanced, I get the following stack trace:
>>>
>>> java.lang.ClassCastException: java.lang.String cannot be cast to 
>>> clojure.lang.Named
>>> at clojure.core$namespace.invoke(core.clj:1497)
>>>  at cljs.compiler$resolve_existing_var.invoke(compiler.clj:110)
>>>  at cljs.compiler$eval1054$fn__1056.invoke(compiler.clj:716)
>>> at clojure.lang.MultiFn.invoke(MultiFn.java:163)
>>>  at cljs.compiler$emit_block.invoke(compiler.clj:333)
>>>  at cljs.compiler$emit_fn_method.invoke(compiler.clj:512)
>>> at cljs.compiler$eval952$fn__954.invoke(compiler.clj:573)
>>>  at clojure.lang.MultiFn.invoke(MultiFn.java:163)
>>> at cljs.compiler$emits.doInvoke(compiler.clj:232)
>>> at clojure.lang.RestFn.invoke(RestFn.java:436)
>>>  at cljs.compiler$eval1089$fn__1091.invoke(compiler.clj:791)
>>> at clojure.lang.MultiFn.invoke(MultiFn.java:163)
>>>  at cljs.compiler$emit_block.invoke(compiler.clj:333)
>>>  at cljs.compiler$eval996$fn__998.invoke(compiler.clj:633)
>>> at clojure.lang.MultiFn.invoke(MultiFn.java:163)
>>> at cljs.compiler$compile_file_STAR_.invoke(compiler.clj:1668)
>>>  at cljs.compiler$compile_file.invoke(compiler.clj:1705)
>>> at cljs.compiler$compile_root.invoke(compiler.clj:1766)
>>>  at cljs.closure$compile_dir.invoke(closure.clj:364)
>>> at cljs.closure$eval1981$fn__1982.invoke(closure.clj:396)
>>> at cljs.closure$eval1910$fn__1911$G__1901__1918.invoke(closure.clj:266)
>>>  at cljs.closure$eval1968$fn__1969.invoke(closure.clj:410)
>>> at cljs.closure$eval1910$fn__1911$G__1901__1918.invoke(closure.clj:266)
>>>  at cljs.closure$build.invoke(closure.clj:874)
>>> at user$compile_cljs.invoke(NO_SOURCE_FILE:273)
>>> at user$cljs_build.invoke(NO_SOURCE_FILE:284)
>>>  at clojure.lang.AFn.applyToHelper(AFn.java:167)
>>> at clojure.lang.AFn.applyTo(AFn.java:151)
>>> at clojure.core$apply.invoke(core.clj:605)
>>>  at clojure.core$partial$fn__4072.doInvoke(core.clj:2345)
>>> at clojure.lang.RestFn.invoke(RestFn.java:408)
>>> at user$changed_fn$fn__2184.invoke(NO_SOURCE_FILE:88)
>>>  at user$watch.invoke(NO_SOURCE_FILE:103)
>>> at user$main$fn__2271.invoke(NO_SOURCE_FILE:387)
>>> at clojure.core$binding_conveyor_fn$fn__3989.invoke(core.clj:1819)
>>>  at clojure.lang.AFn.call(AFn.java:18)
>>> at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
>>> at java.util.concurrent.FutureTask.run(FutureTask.java:138)
>>>  at 
>>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
>>> at 
>>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
>>>  at java.lang.Thread.run(Thread.java:662)
>>>
>>>
>>>
>>>
>>>
>>> On Thursday, 14 June 2012 18:28:56 UTC+10, Dave Sann wrote:

 It may take some time. I'll see what I can do.

 D


 On Thursday, 14 June 2012 00:09:49 UTC+10, David Nolen wrote:
>
> Does this problem only occur on a specific project? Can you create a 
> minimal reproducible case?
>
> Thanks,
> David
>
> On Wed, Jun 13, 2012 at 7:54 AM, 
>
>> So far I can only confirm the following.
>>
>> It does not occur if I revert to commit **
>> 7b6678bead5a0733d0388ddaa4e78e**714b9d6187 but does from **
>> e959e0205a4b42a099c120a7742731**4d288c965b (Merge branch 
>> 'cljs-305-proto-inline') onward.
>>
>> I have been unable to get a stacktrace with the exception - So at the 
>> moment I really don't know why this is occurring.
>>
>> If I find out more I will report it.
>>
>>  Otherwise - I am keen to know if anyone else sees a similar problem.
>>
>> D
>>
>>
>> On Tuesday, 12 June 2012 22:51:39 UTC+10, David Nolen wrote:
>>
>>> That ticket has been resolved. 
>>>
>>> For your o

Re: Is there a reason why 'some' returns "nil" instead o "false"?

2012-06-15 Thread Jim - FooBar();

On 15/06/12 07:27, Tassilo Horn wrote:

"Jim - FooBar();"  writes:


nice catch and point taken...

however the exact same thing would happen if this was a
function...it's just wrong !

Yes.  A correct version is

 (defn in? [coll e]
   (some (partial = e) coll))

Bye,
Tassilo



If just wrapping 'some' I think this is easier to read

 (defn in? [coll e]
  (some #{e} coll))

thanks for your time :-)

Jim

--
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: Is there a reason why 'some' returns "nil" instead o "false"?

2012-06-15 Thread Jim - FooBar();

On 15/06/12 10:47, Jim - FooBar(); wrote:

On 15/06/12 07:27, Tassilo Horn wrote:

"Jim - FooBar();"  writes:


nice catch and point taken...

however the exact same thing would happen if this was a
function...it's just wrong !

Yes.  A correct version is

 (defn in? [coll e]
   (some (partial = e) coll))

Bye,
Tassilo



If just wrapping 'some' I think this is easier to read

 (defn in? [coll e]
  (some #{e} coll))

thanks for your time :-)

Jim


 sorry...you meant to return boolean not the actual element!

my bad...

Jim

--
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: 'dotimes' will not work inside a 'doto'...

2012-06-15 Thread Jim - FooBar();

On 15/06/12 01:00, Andy Fingerhut wrote:
I highly recommend clojuredocs.org  for adding 
examples of pitfalls/traps.  I've added several there myself, e.g. for 
clojure.core/future (and also clojure.core/pmap, clojure.java.shell/sh):


http://clojuredocs.org/clojure_core/clojure.core/future

It takes only a few minutes to do so.

Andy


Thanks Andy I did not know we could do that...

I logged in and added a warning for using 'dotimes' inside a 'doto' 
along with an example of the problem and the 2 remedies that I'm aware 
of...if anyone has any suggestions for making my explanation less 
verbose  - please throw them in ... :-)


Jim

--
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: If a protocol creates a Java interface under the covers...

2012-06-15 Thread Korny Sietsma
You keep talking about performance.  I'm a long way from being a clojure
expert, but one thing I *do* know is that premature optimization is the
root of many many evils.

May I suggest you first get your app working, in a clean understandable
fashion, ideally with some solid unit tests. Then, and only then, profile
it, work out if it performs adequately, and optimise the parts that need it?

(apologies if this is the approach you are already taking - it's bit clear
from your posts if that is the case)

- Korny
On Jun 14, 2012 7:53 PM, "Jim - FooBar();"  wrote:

> On 14/06/12 10:01, nicolas.o...@gmail.com wrote:
>
>> There should not be any atom in this. The function would be more
>> reusable if it take a board and return
>> a board without changing any atom.
>> (You will still be to express the atom change around it but you could
>> also use to try and build a tree without undoing
>> anything.)
>>
>
> Yes you are right nicolas...I  really don't need to reset! the  atom
> inside 'move'...It has been addressed...
>
>  I don't think this approach is extensible enough. You will want to
>> implement more games later.
>> So maybe a good thing is to use protocols or multimethods to represent
>> game rules.
>> The atoms should disappear until later. (You are building a library of
>> moves and rules, there is no notion
>> of state in that. Only when you use it for playing a game on a GUI you
>> will need a state)
>>
>
> I don't want to involve multi-methods in this particular project for
> performance reasons...I do get your point but current-items is only
> fetching the atom or the derefed atom from a game...more game means adding
> a clause so it fetches the appropriate pieces...game rules will be
> implemented in core.logic it has nothing to do with this fn. I do agree I
> will only need the atom when playing an actual game though...
>
>
> Jim
>
>
> --
> 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+unsubscribe@**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: Enfocus issues

2012-06-15 Thread ckirkendall
Thanks for point that out.  It will be fixed shortly.

CK

On Friday, June 15, 2012 1:40:22 AM UTC-4, Andreas Kostler wrote:
>
> There you go...wrong on the example-page then.
> Thanks David
>
>
> On 15 June 2012 15:00, David Nolen  wrote:
>
>> On Fri, Jun 15, 2012 at 1:23 AM, Andreas Kostler <
>> andreas.koest...@leica-geosystems.com> wrote:
>>  
>>> (set! (.onload js/window) start)
>>
>>
>> Should be  (set! (.-onload js/window) start)
>>  
>>  -- 
>> 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: Best practices for named arguments

2012-06-15 Thread Marcus Lindner
I think the best is to use maps. It is rarly a good idea to have too many
arguments.
Am 15.06.2012 08:51 schrieb "David Jacobs" :

> TL;DR: I want to know best practices for designing functions with multiple
> optional arguments.
>
> Okay, so I'm working to build machine learning algorithms in Clojure, and
> they tend to need many arguments. Being a long-time Ruby dev, I like to
> provide sensible defaults for almost all potential arguments that the
> functions take. However, there are some parameters that have to be explicit
> (namely, the data).
>
> To alleviate the pain here, I've started to experiment with named
> arguments. So far, I've come up with something like the following:
>
> (defn descend [xs ys & args]
>   (let [defaults {:gradient-fn gradient
>   :cost-fn cost
>   :yield-fn println
>   :alpha 0.01
>   :iterations 1000
>   :thetas (matrix 0 (second (dim xs)) 1)}
> options (merge defaults (apply hash-map args))
> {:keys [gradient-fn cost-fn yield-fn thetas alpha iterations]}
> options]
> (do-the-algorithm-using-locally-bound-vars)))
>
> It's a little wordy and could be extracted into a macro a la defnk (RIP
> clojure.contrib.def), but it works.
>
> However, if I then want to use method delegation for some algorithms, the
> named argument endeavor gets trickier.
>
> Say I have the same function in two namespaces. One is a general gradient
> descent function, and the other is a specific gradient descent function
> whose only role is to curry a named parameter into the general function.
>
> I want to do something like the following:
>
> (defn descend [xs ys & args]
>   (optimization/descend xs ys (conj args :cost-fn cost)))
>
> The problem, of course, is that if I want to delegate the args array to
> another function, I have to destructure args first before passing it into
> another function. In fact, if I ever have a delegating function like this
> (where a partial apply isn't good enough), I can't pass args through to the
> delegating function because it's automatically vectorized.
>
> How do I splat vectors into parameter lists? (Should I be passing in
> records/maps instead of named parameters?)
>
> Thanks,
> David
>
> --
> 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: Enfocus issues

2012-06-15 Thread ckirkendall
Andreas
Thank you for pointing this out.  I have fixed this on the readme page.  I 
also noticed it is wrong in a few other places.  I will fix them today 
also.  Enfocus also has a google group if you run into more issues.  
https://groups.google.com/group/enfocus


Creighton  

-- 
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: If a protocol creates a Java interface under the covers...

2012-06-15 Thread Jim - FooBar();
Performace was an issue right from the start for this project, that's 
why I went down the protocol/record path instead of 
multi-methods...surely, this is a decision to be made in the beginning, 
isn't it?


I did take into account all the comments so far...my world is now fully 
immutable, reset! is out of 'move', and I've got far less macros 
(replaced them with return-type-hinted fns)...


Also I only starting optimizing (type-hinting) when the namespace 
finished...ok, I did have some design error as it turned out, but it was 
only when I had no more code to write in that namespace that I started 
type-hinting...


I appreciate your concerns though... :-)

Jim

On 15/06/12 12:41, Korny Sietsma wrote:


You keep talking about performance.  I'm a long way from being a 
clojure expert, but one thing I *do* know is that premature 
optimization is the root of many many evils.


May I suggest you first get your app working, in a clean 
understandable fashion, ideally with some solid unit tests. Then, and 
only then, profile it, work out if it performs adequately, and 
optimise the parts that need it?


(apologies if this is the approach you are already taking - it's bit 
clear from your posts if that is the case)


- Korny



--
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: Is there a reason why 'some' returns "nil" instead o "false"?

2012-06-15 Thread Tassilo Horn
"Jim - FooBar();"  writes:


>>> Yes.  A correct version is
>>>
>>>  (defn in? [coll e]
>>>(some (partial = e) coll))
>>
>> If just wrapping 'some' I think this is easier to read
>>
>>  (defn in? [coll e]
>>   (some #{e} coll))
>>
>> thanks for your time :-)
>
>  sorry...you meant to return boolean not the actual element!

No, my variant also returns nil for "e is not in coll", but the
difference is that my version works for nil and false values:

  (in? [nil false] nil)   => true
  (in? [nil false] false) => true

whereas your version with the hash-set returns nil and false in those
cases.

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: clojure.core.cache status?

2012-06-15 Thread Michael Fogus
> and I'm wondering how stable the APIs are and how close a 0.6.0
> release might be?

Very very close. In fact, I will cut a release some time today.

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


Is there a better way to do this

2012-06-15 Thread Joao_Salcedo
HI All,

I am receiving a sequence from a particular function so I want to get that 
sequence and converted to a vector o I can return a vector instead.

(defn get-events-hlpr []
"Retrieves events from MongoDB."
(init)
(def items (mc/find-maps "events")) ;; get the sequence
(loop [vtr []
   data items]
(if (zero? (count data))
vtr
(recur
(conj vtr (dissoc (first data) :_id))(rest data)

Is the right way?

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

clojure-csv library write-csv examples

2012-06-15 Thread octopusgrabbus
I would appreciate getting a pointer to some clojure-csv library write-csv 
examples.

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

Re: clojure-csv library write-csv examples

2012-06-15 Thread octopusgrabbus
The reason why I asked this question is this code looks like it's using 
another csv library, so I'm confused.

(require '[clojure.data.csv :as csv]
 '[clojure.java.io :as io])

(with-open [in-file (io/reader "in-file.csv")]
  (doall
(csv/read-csv in-file)))

(with-open [out-file (io/writer "out-file.csv")]
  (csv/write-csv out-file
 [["abc" "def"]
  ["ghi" "jkl"]]))



On Friday, June 15, 2012 9:57:03 AM UTC-4, octopusgrabbus wrote:
>
> I would appreciate getting a pointer to some clojure-csv library write-csv 
> examples.
>
> 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

Re: Is there a better way to do this

2012-06-15 Thread Walter Tetzner
On Friday, June 15, 2012 9:54:37 AM UTC-4, Joao_Salcedo wrote: 

> Is the right way?
>

You could just do (vec (mc/find-maps "events")).

Also, using def creates a top-level var. You probably wanted (let [items 
(mc/find-maps "events")] ...) instead.

-- 
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: Is there a better way to do this

2012-06-15 Thread Walter Tetzner


> You could just do (vec (mc/find-maps "events")).
>

Also, to dissoc :_id from each item, do (vec (map #(dissoc % :_id) 
(mc/find-maps "events"))).

-- 
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: Is there a better way to do this

2012-06-15 Thread Baishampayan Ghose
> I am receiving a sequence from a particular function so I want to get that
> sequence and converted to a vector o I can return a vector instead.
>
> (defn get-events-hlpr []
> "Retrieves events from MongoDB."
> (init)
> (def items (mc/find-maps "events")) ;; get the sequence
> (loop [vtr []
>   data items]
> (if (zero? (count data))
> vtr
> (recur
> (conj vtr (dissoc (first data) :_id))(rest data)
>
> Is the right way?

Why do you want to return a vector? Do you absolutely need some of the
features that only vectors can provide (indexing, etc.)?

Nevertheless, the code that you wrote is not correct in the Clojure
world. `def` creates a top-level var and that should be only used to
store `global` bindings; `def` is not a way to declare variables.

You should write the code like this instead -

(init) ;; outside, preferably called only once during app initialisation

(defn get-events-hlpr []
  "Retrieves events from MongoDB."
  (vec (mc/find-maps "events")))

Regards,
BG

-- 
Baishampayan Ghose
b.ghose at 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: Best practices for named arguments

2012-06-15 Thread Gunnar Völkel
Hello David.
I have a very similar scenario according to named parameters liker you.
Therefore I have written the library clojure.options which can be found 
here:
https://github.com/guv/clojure.options

The latest version is also on clojars.

Greetings,
Gunnar

-- 
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: Is there a better way to do this

2012-06-15 Thread Tassilo Horn
Baishampayan Ghose  writes:

Hi Baishampayan,

> (defn get-events-hlpr []
>   "Retrieves events from MongoDB."
>   (vec (mc/find-maps "events")))

Is that Emacs Lisp or Common Lisp?

Bye,
Tassilo

Just nitpicking that you adapted the OP's error of adding the docstring
after the parameter vector. ;-)

-- 
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: clojure-csv library write-csv examples

2012-06-15 Thread Walter Tetzner
On Friday, June 15, 2012 10:01:24 AM UTC-4, octopusgrabbus wrote:
>
> The reason why I asked this question is this code looks like it's using 
> another csv library, so I'm confused.
>

That's because it is using another csv library: 
https://github.com/clojure/data.csv.

clojure-csv: https://github.com/davidsantiago/clojure-csv

-- 
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: Is there a better way to do this

2012-06-15 Thread Baishampayan Ghose
> Hi Baishampayan,
>
>> (defn get-events-hlpr []
>>   "Retrieves events from MongoDB."
>>   (vec (mc/find-maps "events")))
>
> Is that Emacs Lisp or Common Lisp?
>
> Bye,
> Tassilo
>
> Just nitpicking that you adapted the OP's error of adding the docstring
> after the parameter vector. ;-)

You are right, Tassilo, I just copied the original code to a scratch
buffer and edited it without looking at the doc-string.

This is how it should be done, really -

(defn get-events-hlpr
  "Retrieves events from MongoDB."
  []
  (vec (map #(dissoc :_id %) (mc/find-maps "events" ;; remove the
:_id as well

Regards,
BG

-- 
Baishampayan Ghose
b.ghose at 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: Calling Clojure from Java and classloader

2012-06-15 Thread Aaron Cohen
On Wed, Jun 13, 2012 at 11:48 PM, Warren Lynn  wrote:
> Ok, I hit a wall and really did not see this coming.
>
> Based on what I have read, its really easy for Clojure and Java to
> work together. So I wrote some test Clojure code with a very simple
> defrecord (say named as "testrec") and AOT compile it, create a jar
> file, and add it to a "HelloWorld" java project in Eclipse. I can
> create object of class "testrec" and run its member functions. Cool,
> no problem.
>
> But then I put the same thing into my target Java system (for which I
> am consider Clojure for production use), I got
> "java.lang.ExceptionInInitializerError" exception when trying to
> create my "testrec" object. A little bit more digging suggests this is
> related to class loader, which I don't know much about. According to a
> web page, I need to do this:
>
> Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
>
> before calling the constructor of my "testrec" class. Tried that, but
> I got
>
> java.security.AccessControlException: access denied
> ("java.lang.RuntimePermission" "setContextClassLoader")
>
> Seems I cannot change the context class loader.
>
> What is the solution here?
>
> Sorry for the long post. But I hope this is not a dead end. Thanks a
> lot.

It's not really a good idea to AOT your code and then directly try to
use it from java. The generated java bytecode isn't guaranteed to be
stable across versions of clojure, and you're depending on
implementation details.

One way to use your clojure code from java is through RT. An example
would be the accepted answer here:
http://stackoverflow.com/questions/2181774/calling-clojure-from-java

Another tack you can take is to use gen-class to create a "real" java
class from clojure and use that as an entry point to your clojure
code.

--Aaron

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


ClojureScript Analyzer Decoupled

2012-06-15 Thread David Nolen
Thanks to Raphael Amiard's hard work the ClojureScript analyzer is now
decoupled:

http://github.com/clojure/clojurescript/commit/9ad79e1c9b87c862ccb7ad6aad37d90414123c76

This is a big step towards making the ClojureScript compiler infrastructure
pluggable. There's a couple of JS things to clean up in the backend and
we're looking to remove any JS specific stuff from cljs.core so that
alternate backends can compile the standard library with no fiddling.

Fun times ahead!

David

-- 
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: ClojureScript Analyzer Decoupled

2012-06-15 Thread Timothy Baldridge
I've been working on a platform-agnostic version of this over here:
https://github.com/halgari/universal-clojure/blob/master/src/universal_clojure/core.clj

But I'd rather collaborate with ClojureScript. Are there any ongoing
efforts to make this cross platform? The current analyzer contains
quite a few java calls. For instance, .contains, and .indexOf. Is
Raphael working on this, or can I take up that torch and implement
these in pure Clojure?

After that, I'd like to rip apart core.cljs and make it also platform
agnostic. My idea is to standardize the native calls under a pseudo
namespace called "native". For instance:

(defn alength [array]
  (native/alength array))

(defn aget [array idx default]
  (if (and (>= idx 0) (< idx (alength array))
  (native/aget array idx))
  default))

All a new platform needs to do is have their compiler interpret
native/alength as the platform specific call (.Length in CLR, len() in
Python, etc.), and the above code is suddenly 100% cross platform.
>From there, porting to a new platform is no longer "translate
core.cljs", but instead, "implement these 20 functions from native/".

I'm really wanting to collaborate on this, since I plan on basing
future versions of Clojure-Py completely off this code base. Any
suggestions on how to go about this? I don't want to re-write anyone
else's code, but I'm also kind of tired of waiting around for someone
to hand me this on a silver platter :-).

Timothy Baldridge



On Fri, Jun 15, 2012 at 11:25 AM, David Nolen  wrote:
> Thanks to Raphael Amiard's hard work the ClojureScript analyzer is now
> decoupled:
>
> http://github.com/clojure/clojurescript/commit/9ad79e1c9b87c862ccb7ad6aad37d90414123c76
>
> This is a big step towards making the ClojureScript compiler infrastructure
> pluggable. There's a couple of JS things to clean up in the backend and
> we're looking to remove any JS specific stuff from cljs.core so that
> alternate backends can compile the standard library with no fiddling.
>
> Fun times ahead!
>
> David
>
> --
> 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



-- 
“One of the main causes of the fall of the Roman Empire was
that–lacking zero–they had no way to indicate successful termination
of their C programs.”
(Robert Firth)

-- 
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: ClojureScript Analyzer Decoupled

2012-06-15 Thread David Nolen
On Fri, Jun 15, 2012 at 1:41 PM, Timothy Baldridge wrote:

> But I'd rather collaborate with ClojureScript. Are there any ongoing
> efforts to make this cross platform? The current analyzer contains
> quite a few java calls. For instance, .contains, and .indexOf. Is
> Raphael working on this, or can I take up that torch and implement
> these in pure Clojure?
>

A bootstrappable compiler infrastructure is not a goal at this point as far
as I know. Certainly open to patches that make the analyzer easier to
compile elsewhere.

If somebody wants to make the compiler bootstrappable they need to outline
some kind of plan that allows ClojureScript (JS) development to continue
with minimal disruption. There are many decisions (non-reified vars and
namespaces, compiler macros, etc.) which make a lot of sense for the
JavaScript target that may not make sense for other targets.


> After that, I'd like to rip apart core.cljs and make it also platform
> agnostic. My idea is to standardize the native calls under a pseudo
> namespace called "native". For instance:
>
> (defn alength [array]
>  (native/alength array))
>
> (defn aget [array idx default]
>  (if (and (>= idx 0) (< idx (alength array))
>  (native/aget array idx))
>  default))
>

Not necessary IMO we have compiler macros - each backend brings their own
compiler macros.


> I'm really wanting to collaborate on this, since I plan on basing
> future versions of Clojure-Py completely off this code base. Any
> suggestions on how to go about this? I don't want to re-write anyone
> else's code, but I'm also kind of tired of waiting around for someone
> to hand me this on a silver platter :-).


Make a Confluence page outlining what you think needs to be done so there
can be some discussion.

David

-- 
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: clojure.core.cache status?

2012-06-15 Thread Sean Corfield
On Fri, Jun 15, 2012 at 6:43 AM, Michael Fogus  wrote:
>> and I'm wondering how stable the APIs are and how close a 0.6.0
>> release might be?
> Very very close. In fact, I will cut a release some time today.

Awesome, thanx! That makes me feel a whole lot better about taking
this puppy to production :)
-- 
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: clojure.core.cache status?

2012-06-15 Thread Michael Fogus
Well, I've tried to cut a release today, but the Hudson build is
complaining about git connection errors. I will try again later today.

-- 
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: Calling Clojure from Java and classloader

2012-06-15 Thread Warren Lynn


> It's not really a good idea to AOT your code and then directly try to 
> use it from java. The generated java bytecode isn't guaranteed to be 
> stable across versions of clojure, and you're depending on 
> implementation details. 
>   
>
One way to use your clojure code from java is through RT. An example 
> would be the accepted answer here: 
> http://stackoverflow.com/questions/2181774/calling-clojure-from-java 
>
>
I really don't like the RT way (very clumsy), so I want to avoid it if 
possible. My .jar file will include Clojure itself in it, so compatibility 
with different version of Clojure is not a problem for me. 
But is there any other pitfalls using AOT?

Another tack you can take is to use gen-class to create a "real" java 
> class from clojure and use that as an entry point to your clojure 
> code. 
>
>
 My understanding is "defrecord" actually generate a real named java class. 
And I can use it in Eclipse project so it seems that is the case.

BTW: my issue is solved by using some kind of annotation defined by the 
target Java framework. However, I could have been in a dead end if there is 
no such annotation and the classloader is messed up. So just as someone 
says "things are never as simple as it seems".



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

Classpath set by lein swank or clojure-jack-in

2012-06-15 Thread Dave Kincaid
One of the things that really been holding me back from moving ahead with 
Clojure is the difficulty I have running code that I'm writing using a 
repl. I generally use Emacs to code Clojure and I really don't understand 
how the classpath gets set when I use either "lein swank + slime-connect" 
or "clojure-jack-in". I can't seem to get it to find either any 
dependencies that I've included in the project.clj or any of my own code 
without a lot of hit and miss trial and error. Eventually I can usually get 
it to work by doing all kind of things like compiling the .clj file, 
launching lein swank from different directories, etc. Is there a good 
document that I could read to understand how I should be doing this. It's 
so frustrating that I don't even want to try writing Clojure code most of 
the time eventhough I'm loving the language.

Thanks,

Dave

-- 
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: Classpath set by lein swank or clojure-jack-in

2012-06-15 Thread Peter Buckley
Once I got lein swank and slime-connect working in emacs, I essentially stopped 
using the repl directly. The real magic and beauty of writing clojure in emacs 
is that I can write a fn, then C-x C-e to evaluate it right there in the file. 
I can evaluate inner forms, test every line of the file to confirm it works, 
experiment, etc, and the code is all saved in the file. 

I don't want to write anything *other* than clojure because it's such a 
beautiful and effective experience. 

-Original Message-
From: Dave Kincaid 
Sender: clojure@googlegroups.com
Date: Fri, 15 Jun 2012 14:47:10 
To: 
Reply-To: clojure@googlegroups.com
Subject: Classpath set by lein swank or clojure-jack-in

One of the things that really been holding me back from moving ahead with 
Clojure is the difficulty I have running code that I'm writing using a 
repl. I generally use Emacs to code Clojure and I really don't understand 
how the classpath gets set when I use either "lein swank + slime-connect" 
or "clojure-jack-in". I can't seem to get it to find either any 
dependencies that I've included in the project.clj or any of my own code 
without a lot of hit and miss trial and error. Eventually I can usually get 
it to work by doing all kind of things like compiling the .clj file, 
launching lein swank from different directories, etc. Is there a good 
document that I could read to understand how I should be doing this. It's 
so frustrating that I don't even want to try writing Clojure code most of 
the time eventhough I'm loving the language.

Thanks,

Dave

-- 
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: Classpath set by lein swank or clojure-jack-in

2012-06-15 Thread Dave Kincaid
I'm with you, Peter. The problem is I can't get lein swank and 
slime-connect working in a consistent way. It starts up fine but can't find 
any dependencies that I try to (use ...) or even any of the code in my .clj 
files that I try to access. I just can't understand what it's using as a 
classpath when it's launched. When I do stumble on the right combination of 
directory, lein swank and emacs buffer it is awesome!

On Friday, June 15, 2012 5:42:59 PM UTC-5, Peter wrote:
>
> Once I got lein swank and slime-connect working in emacs, I essentially 
> stopped using the repl directly. The real magic and beauty of writing 
> clojure in emacs is that I can write a fn, then C-x C-e to evaluate it 
> right there in the file. I can evaluate inner forms, test every line of the 
> file to confirm it works, experiment, etc, and the code is all saved in the 
> file. 
>
> I don't want to write anything *other* than clojure because it's such a 
> beautiful and effective experience. 
> --
> *From: * Dave Kincaid  
> *Sender: * clojure@googlegroups.com 
> *Date: *Fri, 15 Jun 2012 14:47:10 -0700 (PDT)
> *To: *
> *ReplyTo: * clojure@googlegroups.com 
> *Subject: *Classpath set by lein swank or clojure-jack-in
>
> One of the things that really been holding me back from moving ahead with 
> Clojure is the difficulty I have running code that I'm writing using a 
> repl. I generally use Emacs to code Clojure and I really don't understand 
> how the classpath gets set when I use either "lein swank + slime-connect" 
> or "clojure-jack-in". I can't seem to get it to find either any 
> dependencies that I've included in the project.clj or any of my own code 
> without a lot of hit and miss trial and error. Eventually I can usually get 
> it to work by doing all kind of things like compiling the .clj file, 
> launching lein swank from different directories, etc. Is there a good 
> document that I could read to understand how I should be doing this. It's 
> so frustrating that I don't even want to try writing Clojure code most of 
> the time eventhough I'm loving the language.
>
> Thanks,
>
> Dave
>
> -- 
> 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: Classpath set by lein swank or clojure-jack-in

2012-06-15 Thread Moritz Ulrich
That's strange. You usually just run lein swank in the folder with you
project.clj. Nothing to do wrong there.

Can you show the project.clj and the directory structure of a non-working
project?

-- 
Sent from my mobile
Am 16.06.2012 01:07 schrieb "Dave Kincaid" :

> I'm with you, Peter. The problem is I can't get lein swank and
> slime-connect working in a consistent way. It starts up fine but can't find
> any dependencies that I try to (use ...) or even any of the code in my .clj
> files that I try to access. I just can't understand what it's using as a
> classpath when it's launched. When I do stumble on the right combination of
> directory, lein swank and emacs buffer it is awesome!
>
> On Friday, June 15, 2012 5:42:59 PM UTC-5, Peter wrote:
>>
>> Once I got lein swank and slime-connect working in emacs, I essentially
>> stopped using the repl directly. The real magic and beauty of writing
>> clojure in emacs is that I can write a fn, then C-x C-e to evaluate it
>> right there in the file. I can evaluate inner forms, test every line of the
>> file to confirm it works, experiment, etc, and the code is all saved in the
>> file.
>>
>> I don't want to write anything *other* than clojure because it's such a
>> beautiful and effective experience.
>> --
>> *From: * Dave Kincaid 
>> *Sender: * clojure@googlegroups.com
>> *Date: *Fri, 15 Jun 2012 14:47:10 -0700 (PDT)
>> *To: *
>> *ReplyTo: * clojure@googlegroups.com
>> *Subject: *Classpath set by lein swank or clojure-jack-in
>>
>> One of the things that really been holding me back from moving ahead with
>> Clojure is the difficulty I have running code that I'm writing using a
>> repl. I generally use Emacs to code Clojure and I really don't understand
>> how the classpath gets set when I use either "lein swank + slime-connect"
>> or "clojure-jack-in". I can't seem to get it to find either any
>> dependencies that I've included in the project.clj or any of my own code
>> without a lot of hit and miss trial and error. Eventually I can usually get
>> it to work by doing all kind of things like compiling the .clj file,
>> launching lein swank from different directories, etc. Is there a good
>> document that I could read to understand how I should be doing this. It's
>> so frustrating that I don't even want to try writing Clojure code most of
>> the time eventhough I'm loving the language.
>>
>> Thanks,
>>
>> Dave
>>
>> --
>> 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+unsubscribe@**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: Classpath set by lein swank or clojure-jack-in

2012-06-15 Thread Dave Kincaid
Sure can. Here is the project.clj:

(defproject swank-test "0.1"
  :source-path "src/main/clj"
  :test-path "test/clj"
  :java-source-path "src/main/java"
  :javac-options {:debug "true" :fork "true"}
  :resources-path "src/main/resources"
  :dependencies [[org.clojure/clojure "1.4.0"]
 [cascalog "1.9.0"]
 [org.apache.hadoop/hadoop-core "0.20.2" :exclusions 
[hsqldb/hsqldb]]])

I have a file named generator.clj in src/main/clj. When I do a "lein swank" 
from the directory that project.clj is in then run slime-connect in Emacs 
with the generator.clj file open. Then I try to do (use 'generator) and get

Could not locate generator__init.class or generator.clj on classpath: 
  [Thrown class java.io.FileNotFoundException]


what am I doing wrong?

On Friday, June 15, 2012 6:26:02 PM UTC-5, Moritz Ulrich wrote:
>
> That's strange. You usually just run lein swank in the folder with you 
> project.clj. Nothing to do wrong there.
>
> Can you show the project.clj and the directory structure of a non-working 
> project? 
>
> -- 
> Sent from my mobile
> Am 16.06.2012 01:07 schrieb "Dave Kincaid" :
>
>> I'm with you, Peter. The problem is I can't get lein swank and 
>> slime-connect working in a consistent way. It starts up fine but can't find 
>> any dependencies that I try to (use ...) or even any of the code in my .clj 
>> files that I try to access. I just can't understand what it's using as a 
>> classpath when it's launched. When I do stumble on the right combination of 
>> directory, lein swank and emacs buffer it is awesome!
>>
>> On Friday, June 15, 2012 5:42:59 PM UTC-5, Peter wrote:
>>>
>>> Once I got lein swank and slime-connect working in emacs, I essentially 
>>> stopped using the repl directly. The real magic and beauty of writing 
>>> clojure in emacs is that I can write a fn, then C-x C-e to evaluate it 
>>> right there in the file. I can evaluate inner forms, test every line of the 
>>> file to confirm it works, experiment, etc, and the code is all saved in the 
>>> file. 
>>>
>>> I don't want to write anything *other* than clojure because it's such a 
>>> beautiful and effective experience. 
>>> --
>>> *From: * Dave Kincaid  
>>> *Sender: * clojure@googlegroups.com 
>>> *Date: *Fri, 15 Jun 2012 14:47:10 -0700 (PDT)
>>> *To: *
>>> *ReplyTo: * clojure@googlegroups.com 
>>> *Subject: *Classpath set by lein swank or clojure-jack-in
>>>
>>> One of the things that really been holding me back from moving ahead 
>>> with Clojure is the difficulty I have running code that I'm writing using a 
>>> repl. I generally use Emacs to code Clojure and I really don't understand 
>>> how the classpath gets set when I use either "lein swank + slime-connect" 
>>> or "clojure-jack-in". I can't seem to get it to find either any 
>>> dependencies that I've included in the project.clj or any of my own code 
>>> without a lot of hit and miss trial and error. Eventually I can usually get 
>>> it to work by doing all kind of things like compiling the .clj file, 
>>> launching lein swank from different directories, etc. Is there a good 
>>> document that I could read to understand how I should be doing this. It's 
>>> so frustrating that I don't even want to try writing Clojure code most of 
>>> the time eventhough I'm loving the language.
>>>
>>> Thanks,
>>>
>>> Dave
>>>
>>> -- 
>>> 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+unsubscribe@**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: clojure.core.cache status?

2012-06-15 Thread Sean Corfield
On Fri, Jun 15, 2012 at 1:23 PM, Michael Fogus  wrote:
> Well, I've tried to cut a release today, but the Hudson build is
> complaining about git connection errors. I will try again later today.

I saw 0.6.0 on Maven Central - thank you! I'm currently running our
application test suite.
-- 
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


How to do aynchrounous producer/consumer

2012-06-15 Thread Warren Lynn

What I want to do is something I probably have done dozens of times in C++: 
two threads, one thread putting items in a queue, another taking it out 
(FIFO). How to do it in Clojure? I am at a loss. I thought about a few 
options:

1. "watches", but it cannot change the queue itself (can only watch). plus, 
I am not sure watch function will run in another thread
2. "agent", but how to notify the consumer thread when there is new item? 
How to block the consumer thread when there is no items in the queue?
3.  Ping-pong promises: so the producer delivers a promise to the consumer, 
and the consumer immediately deliver another promise to the producer to 
acknowledge the receipt so the producer can move on. But that will prevent 
the producer to put the next item into the queue before the consumer finish 
its processing, so not exactly concurrent.

I cannot believe I am the first one to encounter this. Can anyone suggest 
some idiomatic solution for the above? 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

Re: Classpath set by lein swank or clojure-jack-in

2012-06-15 Thread Sean Corfield
Have you tried visiting the project.clj file in Emacs and then doing
M-x clojure-jack-in ? That should start lein swank in the project
directory and pull in all the dependencies as expected.

(you should start lein swank in the project root directory -
containing project.clj - not in a subdirectory)

On Fri, Jun 15, 2012 at 5:10 PM, Dave Kincaid  wrote:
> Sure can. Here is the project.clj:
>
> (defproject swank-test "0.1"
>   :source-path "src/main/clj"
>   :test-path "test/clj"
>   :java-source-path "src/main/java"
>   :javac-options {:debug "true" :fork "true"}
>   :resources-path "src/main/resources"
>   :dependencies [[org.clojure/clojure "1.4.0"]
>                  [cascalog "1.9.0"]
>                  [org.apache.hadoop/hadoop-core "0.20.2" :exclusions
> [hsqldb/hsqldb]]])
>
> I have a file named generator.clj in src/main/clj. When I do a "lein swank"
> from the directory that project.clj is in then run slime-connect in Emacs
> with the generator.clj file open. Then I try to do (use 'generator) and get
>
> Could not locate generator__init.class or generator.clj on classpath:
>   [Thrown class java.io.FileNotFoundException]
>
>
> what am I doing wrong?

-- 
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: Is there a better way to do this

2012-06-15 Thread Sean Corfield
On Fri, Jun 15, 2012 at 7:30 AM, Baishampayan Ghose  wrote:
> This is how it should be done, really -
>
> (defn get-events-hlpr
>  "Retrieves events from MongoDB."
>  []
>  (vec (map #(dissoc :_id %) (mc/find-maps "events" ;; remove the :_id as 
> well

Or in Clojure 1.4.0 and later:

(defn get-events-hlpr
 "Retrieves events from MongoDB."
 []
 (mapv #(dissoc :_id %) (mc/find-maps "events"))) ;; remove the :_id as well

mapv, filterv and reduce-kv are new in 1.4.0.
-- 
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: Classpath set by lein swank or clojure-jack-in

2012-06-15 Thread Peter Buckley
Probably over-cautious because of my ignorance, but I don't know if I would 
name the project "swank-test" as I haven't paid too close attention to what 
seems a slightly confusing rule about "dashes in namespaces and underscores in 
filenames" - also swank-test might be some sort of existing namespace that 
secretly gets loaded and oddly conflicts. 

I also haven't done much with directory structure under the src/ 
folder - do you have the same problems with a project that only has one file, 
or only files in that folder?

Like I said this is mostly based on my ignorance, and getting a handle on the 
namespacing is probably a good idea, but I've never had an issue with my small 
projects with flat/default directory structures. Might workaround it for you in 
the short term. 

-Original Message-
From: Sean Corfield 
Sender: clojure@googlegroups.com
Date: Fri, 15 Jun 2012 18:44:46 
To: 
Reply-To: clojure@googlegroups.com
Subject: Re: Classpath set by lein swank or clojure-jack-in

Have you tried visiting the project.clj file in Emacs and then doing
M-x clojure-jack-in ? That should start lein swank in the project
directory and pull in all the dependencies as expected.

(you should start lein swank in the project root directory -
containing project.clj - not in a subdirectory)

On Fri, Jun 15, 2012 at 5:10 PM, Dave Kincaid  wrote:
> Sure can. Here is the project.clj:
>
> (defproject swank-test "0.1"
>   :source-path "src/main/clj"
>   :test-path "test/clj"
>   :java-source-path "src/main/java"
>   :javac-options {:debug "true" :fork "true"}
>   :resources-path "src/main/resources"
>   :dependencies [[org.clojure/clojure "1.4.0"]
>                  [cascalog "1.9.0"]
>                  [org.apache.hadoop/hadoop-core "0.20.2" :exclusions
> [hsqldb/hsqldb]]])
>
> I have a file named generator.clj in src/main/clj. When I do a "lein swank"
> from the directory that project.clj is in then run slime-connect in Emacs
> with the generator.clj file open. Then I try to do (use 'generator) and get
>
> Could not locate generator__init.class or generator.clj on classpath:
>   [Thrown class java.io.FileNotFoundException]
>
>
> what am I doing wrong?

-- 
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: Best practices for named arguments

2012-06-15 Thread David Jacobs
Very cool, this is exactly what I wanted. Thanks.

On Friday, June 15, 2012 7:27:05 AM UTC-7, Gunnar Völkel wrote:
>
> Hello David.
> I have a very similar scenario according to named parameters liker you.
> Therefore I have written the library clojure.options which can be found 
> here:
> https://github.com/guv/clojure.options
>
> The latest version is also on clojars.
>
> Greetings,
> Gunnar
>

-- 
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: Classpath set by lein swank or clojure-jack-in

2012-06-15 Thread Dave Kincaid
Thanks I'll give those things a try. swank-test was just a small project I 
threw together as an example for this post. The directory structure is the 
same as my big project though. I'll play around with your suggestions and 
see if I can find a pattern to when it works and when it doesn't.

Thanks,

Dave

On Friday, June 15, 2012 9:10:21 PM UTC-5, Peter wrote:
>
> Probably over-cautious because of my ignorance, but I don't know if I 
> would name the project "swank-test" as I haven't paid too close attention 
> to what seems a slightly confusing rule about "dashes in namespaces and 
> underscores in filenames" - also swank-test might be some sort of existing 
> namespace that secretly gets loaded and oddly conflicts. 
>
> I also haven't done much with directory structure under the 
> src/ folder - do you have the same problems with a project 
> that only has one file, or only files in that folder? 
>
> Like I said this is mostly based on my ignorance, and getting a handle on 
> the namespacing is probably a good idea, but I've never had an issue with 
> my small projects with flat/default directory structures. Might workaround 
> it for you in the short term. 
>
> -Original Message- 
> From: Sean Corfield  
> Sender: clojure@googlegroups.com 
> Date: Fri, 15 Jun 2012 18:44:46 
> To:  
> Reply-To: clojure@googlegroups.com 
> Subject: Re: Classpath set by lein swank or clojure-jack-in 
>
> Have you tried visiting the project.clj file in Emacs and then doing 
> M-x clojure-jack-in ? That should start lein swank in the project 
> directory and pull in all the dependencies as expected. 
>
> (you should start lein swank in the project root directory - 
> containing project.clj - not in a subdirectory) 
>
> On Fri, Jun 15, 2012 at 5:10 PM, Dave Kincaid  
> wrote: 
> > Sure can. Here is the project.clj: 
> > 
> > (defproject swank-test "0.1" 
> >   :source-path "src/main/clj" 
> >   :test-path "test/clj" 
> >   :java-source-path "src/main/java" 
> >   :javac-options {:debug "true" :fork "true"} 
> >   :resources-path "src/main/resources" 
> >   :dependencies [[org.clojure/clojure "1.4.0"] 
> >  [cascalog "1.9.0"] 
> >  [org.apache.hadoop/hadoop-core "0.20.2" :exclusions 
> > [hsqldb/hsqldb]]]) 
> > 
> > I have a file named generator.clj in src/main/clj. When I do a "lein 
> swank" 
> > from the directory that project.clj is in then run slime-connect in 
> Emacs 
> > with the generator.clj file open. Then I try to do (use 'generator) and 
> get 
> > 
> > Could not locate generator__init.class or generator.clj on classpath: 
> >   [Thrown class java.io.FileNotFoundException] 
> > 
> > 
> > what am I doing wrong? 
>
> -- 
> You received this message because you are subscribed to the Google 
> Groups "Clojure" group. 
> To post to this group, send email to clojure@googlegroups.com 
> Note that posts from new members are moderated - please be patient with 
> your first post. 
> To unsubscribe from this group, send email to 
> clojure+unsubscr...@googlegroups.com 
> For more options, visit this group at 
> http://groups.google.com/group/clojure?hl=en

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

Re: How to do aynchrounous producer/consumer

2012-06-15 Thread Alan Malloy
(map consume (seque (produce-lazily)))

On Friday, June 15, 2012 6:44:39 PM UTC-7, Warren Lynn wrote:
>
>
> What I want to do is something I probably have done dozens of times in 
> C++: two threads, one thread putting items in a queue, another taking it 
> out (FIFO). How to do it in Clojure? I am at a loss. I thought about a few 
> options:
>
> 1. "watches", but it cannot change the queue itself (can only watch). 
> plus, I am not sure watch function will run in another thread
> 2. "agent", but how to notify the consumer thread when there is new item? 
> How to block the consumer thread when there is no items in the queue?
> 3.  Ping-pong promises: so the producer delivers a promise to the 
> consumer, and the consumer immediately deliver another promise to the 
> producer to acknowledge the receipt so the producer can move on. But that 
> will prevent the producer to put the next item into the queue before the 
> consumer finish its processing, so not exactly concurrent.
>
> I cannot believe I am the first one to encounter this. Can anyone suggest 
> some idiomatic solution for the above? 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

Re: A tutorial for how to setup your clojure development environment for: Emacs, Leiningen and Linux.

2012-06-15 Thread Sean Corfield
On Thu, Jun 14, 2012 at 11:28 PM, fenton  wrote:
> What I'd suggest is that there be a git repo for clojure docs, where things
> can be brought together like the types of articles i'm writing, but tended
> by the clojure community.

Phil has streamlined
http://dev.clojure.org/display/doc/Getting+Started+with+Emacs and now
all the actual documentation is in the clojure-mode repo (and the
swank-clojure repo - for SLIME/Swank setup). That means anyone can
fork, update and send a pull request.
-- 
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: ANN: lambic v. 0.1.0

2012-06-15 Thread Peter Taoussanis
I don't know the first thing about logic programming so can't say whether 
something like this would be practical to implement or not - but boy what a 
neat idea!

I'm constantly needing to restructure bits of data and while it's not 
exactly tough to do in Clojure, something like this would certainly be 
welcome.

I hope you can figure out a way of making this work. I'll try take a look 
again once you've got some examples up to see if there's anything I could 
contribute.

Cheers!

- Peter Taoussanis (@ptaoussanis)

>

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