Fork me on GitHub
#clojure
<
2017-05-23
>
kzeidler00:05:31

Aha: (def foo (atom {:a {:b 2}}))

wiseman00:05:40

in that ring buffer code @noisesmith linked to, what’s the purpose of the lazy-seq here:

Object
  (toString [this]
    (pr-str (lazy-seq (seq this))))

noisesmith00:05:35

Honestly, I don't know I'd think str of seq would suffice

jumar07:05:37

@iluk true? returns true only if param is a single true value (using identical) - see doc and source. you'll get the same result if you create a new Boolean instance:

iluk07:05:53

single true?

iluk07:05:20

filter and remove doesn't work on my collection which consists from those kind of 'true"s

iluk07:05:56

how do I check this kind of true for trustiness?

mpenet08:05:38

but using boolean constructor is usually a sign somebody is doing something wrong

iluk08:05:29

thank you

iluk08:05:36

it generates clojure code for selenium webdriver

matan10:05:46

I read about reducers and transducers the other day. Of course they make perfect sense, and also exist in other languages, sometimes at the core.

matan10:05:23

Why or when however, should we ever opt for reducers rather than transducers, at present time?

val_waeselynck10:05:07

It's an answer by Alex Miller, so pretty authoritative I would say

val_waeselynck10:05:43

@matan by the way, in what other languages have you seen transducers ?

matan11:05:04

@val_waeselynck and @alexmiller thanks! this kind of clears it up!! 🙂 maybe I'll grab a copy of https://www.amazon.com/Clojure-Applied-Practitioner-Ben-Vandgrift/dp/1680500740, hopefully the kindle version is readable on a kindle device, with non-prose you never know 😩

matan11:05:35

What else I didn't get about transducers is the fine print at https://clojure.org/reference/transducers > If you have a new context for applying transducers, there are a few general rules to be aware of: > • If a step function returns a reduced value, the transducible process must not supply any more inputs to the step function. The reduced value must be unwrapped with deref before completion. > • A completing process must call the completion operation on the final accumulated value exactly once. > • A transducing process must encapsulate references to the function returned by invoking a transducer - these may be stateful and unsafe for use across threads.

luxbock11:05:43

@matan I read it on Kindle and it was quite good compared to many other programming books

matan11:05:01

luxbock: great good to know! looks like a terrific book!

matan12:05:44

@U054D2JUV which form factor was it actually? a physical kindle device?

luxbock13:05:03

yes a physical Kindle device

matan11:05:47

I must be too idiotic to fathom those important caveats and comments without an example

luxbock11:05:47

@matan @cgrand recently gave a talk where he talks about the pitfalls that those caveats present for someone writing a transducer or a transduction context: https://youtu.be/XiCwN-fv7os

luxbock11:05:05

and his xforms library has a cool trial transduction context function for testing that a transducer respects these contracts

luxbock11:05:35

for most people it's quite rare to write new transducers or transduction contexts

luxbock11:05:14

https://github.com/MastodonC/kixi.stats is a cool library that performs statistical computations using transducers

matan12:05:55

@cgrand mmm I guess the topic is a little complex, will try to watch there

matan12:05:22

> "often left me in a deep state of despair and frustration" what a nice opening for a video about transducers 😂

qqq12:05:23

is behavior defined when a *.cljC file contains defmacros ;; if so, how ?

plexus13:05:45

anyone know how to make sure data_readers.clj gets loaded when running from an uberjar? I have this src/data_readers.clj, which locally gets picked up by Clojure automatically, but somehow when running from an uberjar it doesn't get loaded

{joda/inst lambdaisland.util.time/->joda-inst}

pesterhazy13:05:43

can you verify that data_readers.clj is in the jar?

pesterhazy13:05:17

it needs to be in the root of the classpath

cgrand13:05:25

@qqq it depends on a lot of things (are there a .clj or .cljs files shadowing the .cljc, which cljs do you target etc.)

plexus13:05:13

@pesterhazy the jar is created with lein uberjar, data_readers.clj is definitely there, in the root of the jar

plexus13:05:47

owww but it's a different data_readers.clj, some other version of it is getting pulled in

plexus13:05:06

working around it with doing an explicit (alter-var-root #'*data-readers* (fn [r] (assoc r 'joda/inst #'lambdaisland.util.time/->joda-inst)))

pesterhazy14:05:39

I think.... there can be multipiple data_readers.clj:

pesterhazy14:05:42

>>> When Clojure starts, it searches for files named data_readers.clj at the root of the classpath. Each such file must contain a Clojure map of symbols, like this:

pesterhazy14:05:09

not sure how a jar can contain multiple files names data_readers.clj in the same path though

pesterhazy14:05:02

hm I guess the answer is that a jar cannot contain multiple files with the same name, but running clojure with a classpath containing multiple jars or directories can

plexus14:05:33

I'm getting the impression that lein uberjar merges multiple data_readers.clj into one, since there's stuff in there provided by several different libraries, and there seems to be some merging logic in lein uberjar, as well as an undocumented :uberjar-merge-with configuration flag. I tried this though, based on what I could find, but doesn't seem to help :uberjar-merge-with {"data_readers.clj" leiningen.uberjar/clj-map-merger}

qqq14:05:35

I heard concat is bad because it is lazy. What is the ocrrect wa yto concat [[1 2] [3 4] [5 6]] into [1 2 3 4 5 6] ?

mpenet14:05:15

lazy is not bad, but you can (into [] cat [[1 2] [3 4] [5 6]])

spei15:05:18

(vec (concat [[1 2] [3 4] [5 6]])

tbaldridge15:05:56

@qqq it's recursive concat you have to watch out for

mpenet15:05:11

@spei that one will generate an intermediary (lazy) seq

tbaldridge15:05:13

unbounded recursive concat at that

noisesmith15:05:12

I’d say the issue is as much strictness as laziness - people use a strict looping construct like reduce or loop to stack calls to lazy concat without realizing any of them - take either factor out and the problem goes away

noisesmith15:05:32

just lazy or just strict doesn’t hit the issue

spei15:05:17

@mpenet oh interesting. i didn't really think that there was a true intermediate product there.

spei15:05:31

does ((comp vec concat) [[1 2] [3 4] [5 6]]) also generate the intermediate lazy seq?

noisesmith15:05:35

@spei clojure doesn’t do “stream fusion” - if something returns lazy seq, that is never optimized out, no matter what you use the lazy seq for

mpenet15:05:15

yep, no compiler magic for us. but transducers are actually nicer imho

noisesmith15:05:19

(I guess you could call the way reduce uses eg. range an optimization of that sort, but that’s built into the definition of range…)

mpenet15:05:53

well you can build your own on top of IReduceInit

mpenet15:05:05

but it's not really documented I think

mpenet15:05:12

but here to stay I would guess

octahedrion15:05:45

what's the best way to provide a clean way to create objects (deftype...) that can come in x kinds of y varieties of z types ? I'm guessing multimethods

noisesmith15:05:04

what are the types for? why do you need all these types?

octahedrion16:05:55

for different implementations of the same protocol varying according to different algorithms

octahedrion16:05:26

...and the algorithms come in different categories

Alex Miller (Clojure team)16:05:50

you might look at multimethods and keyword hierarchies as another possible option

octahedrion16:05:12

right - have never used hierarchies ok will read up

octahedrion16:05:34

it's basically a way to organize a big cube of algorithms all of which have a common simple interface

byron-woodfork17:05:33

Hey, anyone have any recommended machine learning (in clojure) resources? Open source library's, blog posts, books, etc.

john17:05:35

Haven't read it

john17:05:16

Incanter is an R-like environment for data exploration: https://github.com/incanter/incanter

john17:05:51

and Cortex is a neat new neural network implementation: https://github.com/thinktopic/cortex

michaellindon17:05:08

@byron-woodfork I have a distributions library that i am working on, with base distributions that are wrappers of apache commons math distributions, though i havent written any documentation. https://github.com/michaellindon/distributions/tree/master/src/distributions

michaellindon18:05:04

I also have some software for feature selection in regression models: https://michaellindon.github.io/software/sss4clj/index.html

wiseman18:05:28

i haven’t been able to find a word2vec implementation in java/clojure that is fast enough to be usable, unfortunately.

mpenet18:05:17

wiseman: did you chech deeplearning4j?

wiseman18:05:50

yes, and it was much slower than e.g. python’s gensim library. i haven’t tried in a few months though, i could give it another go

matan03:05:10

@U07HVL0F7 why do you need it in java? typically a word embedding is generated just once (can use word2vec as a bash command from clojure) and then put to work in an application which can be clojure in our case

matan03:05:23

there are utilities to convert word embeddings file formats for such portability

wiseman03:05:43

in python, loading e.g. the pre-trained GoogleNews word2vec model takes a minute or two, and then queries are sub-second. in java, just querying the model takes several seconds--enough to make it unusable for interactive use.

wiseman03:05:10

so i’m not even talking about training--just using an existing model is too slow.

wiseman03:05:46

so sure, i could just use some sort of IPC and not actually use a java implementation--but that’s not my ideal situation

john18:05:00

This also seems cool, for NLP work: https://github.com/fekr/postagga

john18:05:40

GigaSquid also has a bunch of great Clojure/ML related blog posts worth reading: http://gigasquidsoftware.com/#/blog/archives/index

jsa-aerial20:05:29

@byron-woodfork There are actually quite a few of these - some noted here. Try #data-science, that is where people working with this more typically hang out.