Fork me on GitHub
#clojure
<
2018-07-03
>
cristibalan00:07:50

@bronsa Sadly, after much printing I have discovered that eventually some of the contents of two were being checked with (list? x) ๐Ÿ˜ž The 'broken' two contained LazySeq where the 'working' two had PersistentList.

noisesmith00:07:42

yeah, list? is something you probably shouldn't ever use in clojure code

๐Ÿ˜ญ 4
cristibalan01:07:40

I just wish I hadn't spent half a day finding out about it ๐Ÿ˜•

noisesmith01:07:42

it's semi-documented on clojuredocs http://clojuredocs.org/clojure.core/list_q

;; So seq? might be what you are looking 
;; for when you want to test listness.

cristibalan01:07:22

I actually looked it up there and skimmed the examples a bit. But it appears I dit not completely rtfm as this is the last line ๐Ÿ˜•

cristibalan01:07:24

I think I was on tilt and could not accept the outrageousness of the bug I was facing.

noisesmith01:07:37

the warning could / should probably be much clearer and emphatic

cristibalan01:07:35

To be fair, my code was pretty big and involved and it was at the end of a big series of steps after I had mostly worked with literals in the repl. Then bumped into this when using real data and there were too many things going on to notice the silly list? hiding somewhere.

cristibalan01:07:34

But, yeah. If it's such a bad idea to generally use list? maybe it could help newbies if it weren't so easy to end up there.

bmaddy02:07:40

Does anyone see what I'm doing wrong here? I have a deps.edn that looks like this:

{:deps
 {org.wikidata.wdtk/wdtk-dumpfiles {:mvn/version "0.8.0"}}}
I expect to see a class in that library like this, but get an error:
$ clj
Clojure 1.9.0
user=> org.wikidata.wdtk.wikibaseapi.WikibaseDataFetcher
CompilerException java.lang.ClassNotFoundException: org.wikidata.wdtk.wikibaseapi.WikibaseDataFetcher, compiling:(NO_SOURCE_PATH:0:0) 
I'm trying to follow some java code here https://github.com/Wikidata/Wikidata-Toolkit-Examples/blob/master/src/examples/FetchOnlineDataExample.java#L30 and here https://www.mediawiki.org/wiki/Wikidata_Toolkit#Download_and_installation Is there some way to list the classes in a dependency?

bmaddy03:07:05

Yep, that did it. Thanks @hiredman!

hiredman03:07:51

including one with wikibaseapi in the name

emccue07:07:56

Ive been thinking about stuff like that recently. Theres alot of things in core that are landmines like contains?

emccue07:07:48

I wonder what the best way would be to support a streamlined-core at the library level

emccue07:07:36

Or even an alternate-core

noisesmith11:07:23

To me contains? is very useful. The fact that it only works on indexed data structures is OK. As opposed to list? where not only does it not do what you think, it also isn't ever useful.

noisesmith11:07:27

Clojure is a small language, I think learning what each function in clojure.core is for isn't a huge problem, and doesn't require a new wrapper.

djtango12:07:13

hey folks- curious to know how people deal with libraries which use extend-protocol in contradicting ways. Say you have one lib that wants to cast all DB dates into string and you want to require that lib but your lib wants to cast all dates into joda dates, is there a way to scope your protocols by namespace/context

mpenet12:07:22

libs should make this parts optional when they want to provide this, or make the codec first class (ex an argument)

anton14:07:42

Does anyone know how to get a clojure REPL set up, possibly with Boot?

anton14:07:07

I was originally working on a Clojurescript project but the errors got so incomprehensible that I decided to try developing it in Clojure instead, however I can't figure out how to get the same REPL experience

manutter5115:07:15

What editor/IDE are you using?

anton15:07:52

currently Sublime, although I'm planning on moving to CIDER sometime soon

theeternalpulse15:07:17

why does this evaluate to true (realized? (iterate dec 1))

theeternalpulse15:07:58

from my understanding iterate should be lazy and since I'm not using doall or just evaluating it in the repl it shouldn't be realized

hiredman16:07:36

realized? is dumb

โž• 4
theeternalpulse16:07:53

ah, I get when wrapping it in something like take or while it shows as false, but I don't know of the quirks of realized?

ghadi16:07:13

agree with @hiredman - realized? shouldn't be used

ghadi16:07:54

either you have values from a sequence or you don't, don't test whether the sequence itself has been touched and how

jdkealy16:07:01

Hi, I'm trying to process an HTTP stream using core.async. I saw this answer on stack overflow. https://stackoverflow.com/questions/30125909/processing-a-stream-of-messages-from-a-http-server-in-clojure But my function hangs when I call (line-seq ) on the stream. I'm able to write the stream to a file but stuck on processing each message and putting it on a channel.

emccue16:07:33

@noisesmith Yeah its relatively small, but having the parts of clojure that require a "wtf" google at hand at all times is something that I personally don't want.

emccue16:07:09

Like, I would rather have to lookup and explicitly import realized? than to have it always at hand

emccue16:07:38

I've done that by accident a few times too ^

noisesmith16:07:42

Wait, what's wrong with realized??

emccue16:07:15

not sure, still reading, but my impression is based off of @hiredmanโ€™s comment

emccue16:07:41

and that small discussion

noisesmith16:07:23

I only use it on promises and delays

noisesmith16:07:01

I think knowing when specific functions are appropriate isn't too much to ask, especially with the core lib being as small and relatively internally consistent as it is

noisesmith16:07:50

I would find code that ignored clojure.core and used some "better core" frustrating. I would take these concerns into account if I was making a new language though

emccue16:07:06

Why would you find it frustrating?

noisesmith16:07:56

Because it's using a new language that I don't know.

emccue16:07:06

thats fair

noisesmith17:07:56

1) I don't see any usage of core.async here 2) are you sure there are any line breaks in the input? what if you temporarily split on bytes instead?

noisesmith17:07:36

line-seq will block until it finds at least one newline or end of input, depending on the input source you might need something more custom

jdkealy17:07:30

hey sorry i haven't implemente the core async part as i have nothing to put on a channel yet

jdkealy17:07:45

ok that's interesting... but when i write to a file it works perfectly

jdkealy17:07:36

If I do the following and tail the file, the file grows in length

(with-open [in-stream (:body (client/get url {:as :stream}))
            out-stream (->> "streamoutput.txt"
                        io/as-file
                        io/output-stream)]
  (io/copy in-stream out-stream))

jdkealy17:07:50

so... right i'm not sure there are line breaks

noisesmith17:07:36

it might be easier to test your code with a StringReader, then if it only misbehaves on your stream and not a StringReader, you know it's something about that stream not looking like the input you are testing with

jdkealy17:07:34

it prints one line at a time it seems

jdkealy18:07:21

when i write to a file it outputs XML

noisesmith18:07:39

there's something up with that host, it's either flaky or doing client detection - one time it timed out, another it gave me a 401

noisesmith18:07:12

try your code on any actual site (like a google search or whatever)

jdkealy18:07:08

i think the sessionid timed out ๐Ÿ˜ž

hiredman18:07:17

I got an invalid xml file, all on a single line (possible streamed infinitely large)

noisesmith18:07:10

yeah, line-seq on that wouldn't be a great idea

noisesmith18:07:48

but xml-seq might work ?? - I don't know if it streams properly

noisesmith18:07:28

I once tried to consume xml as a lazy stream, I got nodes lazily but the underlying library didn't clean up properly unless I consumed all the way to the end, leading to a resource leak in my usage case

jdkealy18:07:45

so... xml-seq does return a sequence

jdkealy18:07:54

but the first item in the sequence is a filterinputstream

noisesmith18:07:18

it's meant to be used with parse, and I'm not certain it's well behaved for streaming

jdkealy18:07:02

wow it works

jdkealy18:07:12

thank you so much... and wow this XML sucks haha

noisesmith18:07:46

> wow this XML sucks why repeat yourself :D

noisesmith18:07:02

"wow this is xml"

sobel20:07:12

i have an odd problem with my uberjar... my code creates a URL (io/resource) successfully when i "lein run" but when i "java -jar" the URL is null

sobel20:07:28

the resource is in a mvn dependency

hiredman20:07:07

is it actually in the jar?

arrdem20:07:26

If youโ€™re just jaring not uberjaring the resource wonโ€™t be in your jar.

sobel20:07:21

it's definitely in the jar; i checked with jar tf | less

dpsutton21:07:46

the other day there was an argument if an argument n contolled the degree of parallel of a function. but it wasn't pmap i don't think. does anyone recall that?

noisesmith21:07:54

the one about pmap was the only one like that, but n isn't an argument to pmap, it's calculated based on CPU count

noisesmith21:07:29

but the value in pmap's let binding was called n

dpsutton21:07:32

ahhh. it was the n in its implementation that yall were discussing. thanks @noisesmith

noisesmith21:07:56

the answer ended up being that the true parallelism ends up being n+chunk-size

noisesmith21:07:09

where chunk-size is implemented by the source collection you map over

noisesmith21:07:00

and n is the number of cpus you have available to the vm, +2

dpsutton21:07:58

thanks. we were just talking about it and i remembered loosely following but not what the conclusion was

noisesmith21:07:54

another way of putting it is "it uses futures to stay n+2 steps ahead of the realization of the lazy-seq" - so chunking just means you realize items faster and don't actually speed up the dispatch if you look at it that way

kennytilton22:07:08

empty? does not like transient maps. I went with checking for a count of zero, but did I miss something? Did not find an empty?!.

kennytilton22:07:50

CompilerException java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.PersistentHashMap$TransientHashMap

noisesmith22:07:45

transients are weird

andy.fingerhut22:07:55

Has been known about for years. Looks like Rich has marked it for fixing in version 1.10

noisesmith22:07:30

it just seems like you run into things like that easily if you leave a narrow happy path with transients

andy.fingerhut22:07:35

Or rather Alex Miller has marked it so, which is the next best thing

andy.fingerhut22:07:18

Yes, the narrow happy path with transients is to convert a persistent collection to a transient, do only 'update' operations ending in ! on it, then convert it back to a persistent collection.

kennytilton14:07:07

Oh, cool, overnight I decided independently to see if a vector would be faster for my use case, and @noisesmith will be happy to learn it will have 26 items. Life is good.

kennytilton14:07:55

Actually, it looks as if a simple int-array will be as fast and support mutation. Learning a lot.

kennytilton12:07:50

Nope, did much better with the transient. Learned a lot. ๐Ÿ™‚

noisesmith22:07:08

and be sure to use collections with more than 16 items in your unit test :D

simple_smile 4