Re: Transducers eduction vs sequence

2017-12-22 Thread Jonathon McKitrick
Ah, ok. I guess I was thrown off because evaluating sequence and eduction 
results both produce output at the REPL, but only sequence can be output as 
JSON at the REPL.

On Friday, December 22, 2017 at 1:46:59 PM UTC-5, Sean Corfield wrote:
>
> Their respective docstrings give a hint here:
>
>  
>
> Sequence – “returns a lazy sequence”.
>
> Eduction – “returns a reducible/iterable …”.
>
>  
>
> (type (sequence identity [1 2 3])) => clojure.lang.LazySeq
>
> (type (eduction identity [1 2 3])) => clojure.core.Eduction
>
>  
>
> If you look at that cheshire.generate/generate function -- 
> https://github.com/dakrone/cheshire/blob/master/src/cheshire/generate.clj#L116-L152
>  
> – you’ll see it is a large cond on the type of its argument and that it 
> supports clojure.lang.ISeq (which clojure.lang.LazySeq implements) but does 
> not support any of the types that clojure.core.Eduction has behind it.
>
>  
>
> If you wrap your eduction call in a seq call, I expect it will work:
>
>  
>
> (type (seq (eduction identity [1 2 3]))) => clojure.lang.LazySeq
>
>  
>
> Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN
> An Architect's View -- http://corfield.org/
>
> "If you're not annoying somebody, you're not really alive."
> -- Margaret Atwood
>
>  
> --
> *From:* clo...@googlegroups.com   > on behalf of Jonathon McKitrick  >
> *Sent:* Friday, December 22, 2017 6:32:54 AM
> *To:* Clojure
> *Subject:* Transducers eduction vs sequence 
>  
> I have a `get-summary` function that builds stats and returns them as a 
> web service. Under the hood, it calls quite a few map, group-by, filter, 
> etc. functions. 
>
> I’m experimenting with transducers, and `sequence xform` does the trick 
> most of the time. But I want to understand `eduction` use cases. In most 
> cases, `eduction` seems to be a drop-in replacement. But in a few cases, 
> I’m seeing this error:
>
> JsonGenerationException Cannot JSON encode object of class: class 
> clojure.core.Eduction: clojure.core.Eduction@31accd87 
>  cheshire.generate/generate (generate.clj:152)
>
> So there’s something I’m missing about my understanding of `sequence` 
> versus `eduction`. Can someone shine some light on it?
>
> Thanks!
>
> -- 
> 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: Understanding remove-ns and require

2017-12-22 Thread Mikhail Gusarov


On Fri, 22 Dec 2017, at 18:41, Stuart Sierra wrote:
> Also be aware that AOT-compilation[1] causes all sorts of havoc with
> namespace reloading, because AOT-compiled .class files get read by a
> different ClassLoader.> 

Is there any place explaining how exactly Clojure compiles and loads the
code? It always feels like magic (especially when it does not work).
Names of source code files work too.

Links:

  1. https://clojure.org/reference/compilation

-- 
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: Transducers eduction vs sequence

2017-12-22 Thread Francis Avila
Even though evaluation and realization of sequences is lazy, they cache 
their result after evaluation. If you consume an object from the `sequence` 
function more than once, the work is only done once. Sequences are iterable 
and reducible, but not as efficiently because of the caching and because 
internally they have a linked-list structure (pointers rather than arrays).

`sequence` produces pretty much the same thing as "normal" lazy-sequence 
clojure. `(sequence (map f) xs)` and `(map f x)` are equivalent.

`eduction` produces an object that does not cache the result of transducer 
transformations. It's iteration and reduction implementations are faster, 
but the result is not cached.

Your error is because cheshire does not know how to serialize an Eduction 
object to Json.

On Friday, December 22, 2017 at 8:32:54 AM UTC-6, Jonathon McKitrick wrote:
>
> I have a `get-summary` function that builds stats and returns them as a 
> web service. Under the hood, it calls quite a few map, group-by, filter, 
> etc. functions.
>
> I’m experimenting with transducers, and `sequence xform` does the trick 
> most of the time. But I want to understand `eduction` use cases. In most 
> cases, `eduction` seems to be a drop-in replacement. But in a few cases, 
> I’m seeing this error:
>
> JsonGenerationException Cannot JSON encode object of class: class 
> clojure.core.Eduction: clojure.core.Eduction@31accd87 
>  cheshire.generate/generate (generate.clj:152)
>
> So there’s something I’m missing about my understanding of `sequence` 
> versus `eduction`. Can someone shine some light on it?
>
> 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/d/optout.


RE: Transducers eduction vs sequence

2017-12-22 Thread Sean Corfield
Their respective docstrings give a hint here:

Sequence – “returns a lazy sequence”.
Eduction – “returns a reducible/iterable …”.

(type (sequence identity [1 2 3])) => clojure.lang.LazySeq
(type (eduction identity [1 2 3])) => clojure.core.Eduction

If you look at that cheshire.generate/generate function -- 
https://github.com/dakrone/cheshire/blob/master/src/cheshire/generate.clj#L116-L152
 – you’ll see it is a large cond on the type of its argument and that it 
supports clojure.lang.ISeq (which clojure.lang.LazySeq implements) but does not 
support any of the types that clojure.core.Eduction has behind it.

If you wrap your eduction call in a seq call, I expect it will work:

(type (seq (eduction identity [1 2 3]))) => clojure.lang.LazySeq

Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood


From: clojure@googlegroups.com  on behalf of Jonathon 
McKitrick 
Sent: Friday, December 22, 2017 6:32:54 AM
To: Clojure
Subject: Transducers eduction vs sequence

I have a `get-summary` function that builds stats and returns them as a web 
service. Under the hood, it calls quite a few map, group-by, filter, etc. 
functions.

I’m experimenting with transducers, and `sequence xform` does the trick most of 
the time. But I want to understand `eduction` use cases. In most cases, 
`eduction` seems to be a drop-in replacement. But in a few cases, I’m seeing 
this error:

JsonGenerationException Cannot JSON encode object of class: class 
clojure.core.Eduction: clojure.core.Eduction@31accd87  
cheshire.generate/generate (generate.clj:152)

So there’s something I’m missing about my understanding of `sequence` versus 
`eduction`. Can someone shine some light on it?

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/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: Understanding remove-ns and require

2017-12-22 Thread Andy Fingerhut
If you do have namespace names that do not correspond with the file name
they are placed in, in a Clojure/Java files, Eastwood can find them for you
quickly.  Eastwood doesn't analyze ClojureScript files, though.

Andy

https://github.com/jonase/eastwood


On Fri, Dec 22, 2017 at 9:41 AM, Stuart Sierra 
wrote:

> => CompilerException java.lang.Exception: namespace 'foo.bar' not found
>> after loading '/foo/bar', compiling:(*cider-repl foo*:65:7)
>>
>
> An error like this usually means that the ns declaration does not match
> the expected namespace name, based on the file path.
>
> Also be aware that AOT-compilation
>  causes all sorts of havoc
> with namespace reloading, because AOT-compiled .class files get read by a
> different ClassLoader. In effect, you cannot "unload" an AOT-compiled
> namespace. Make sure you do not have any AOT-compiled .class files in your
> project, and note that some tools and templates enable AOT by default.
>
> –S
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> 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: Understanding remove-ns and require

2017-12-22 Thread Stuart Sierra

>
> => CompilerException java.lang.Exception: namespace 'foo.bar' not found 
> after loading '/foo/bar', compiling:(*cider-repl foo*:65:7)
>

An error like this usually means that the ns declaration does not match the 
expected namespace name, based on the file path.

Also be aware that AOT-compilation 
 causes all sorts of havoc with 
namespace reloading, because AOT-compiled .class files get read by a 
different ClassLoader. In effect, you cannot "unload" an AOT-compiled 
namespace. Make sure you do not have any AOT-compiled .class files in your 
project, and note that some tools and templates enable AOT by default.

–S

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


Transducers eduction vs sequence

2017-12-22 Thread Jonathon McKitrick
I have a `get-summary` function that builds stats and returns them as a web 
service. Under the hood, it calls quite a few map, group-by, filter, etc. 
functions.

I’m experimenting with transducers, and `sequence xform` does the trick 
most of the time. But I want to understand `eduction` use cases. In most 
cases, `eduction` seems to be a drop-in replacement. But in a few cases, 
I’m seeing this error:

JsonGenerationException Cannot JSON encode object of class: class 
clojure.core.Eduction: clojure.core.Eduction@31accd87 
 cheshire.generate/generate (generate.clj:152)

So there’s something I’m missing about my understanding of `sequence` 
versus `eduction`. Can someone shine some light on it?

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/d/optout.