Fork me on GitHub
#clojure
<
2016-12-31
>
bbloom00:12:53

@bradford you can just use ExecutorService directly if you like

bbloom00:12:15

regular clojure functions are Runnable already

bbloom00:12:43

as a general rule, if the host facility is good, clojure doesn’t try to replace it

qqq00:12:14

is there an alternative to -> or ->> where it's (----> arg f1 f2 f3 f4) where the fi's are all of the form #( .... % ... ) ?

qqq00:12:24

i.e. after the first arg, all the exprs result in functions which take just 1 arg

qqq00:12:30

and I want to thread the arg through all the functions

qqq00:12:02

@bbloom: this works; thanks!

bradford02:12:38

@mingp Thanks! I was looking at that but didn't see anything for timeouts

qqq03:12:34

Besides Red5/Java, are there any other libraries for building live video streaming (like twitch ) in Clojure?

qqq07:12:01

src/bar/foo.clj <-> src/bar/foo_test.clj is becoming really annoying; is there any downsides to using test/bar/foo_test.clj ?

seancorfield07:12:09

Not sure what you're asking there @qqq -- most people have tests in the test subtree and source in the src subtree...

qqq07:12:24

@seancorfield: I guess I was asking "is there anything bad if I stop kicking this rock" ;; I originally had impl/code in the same directory due to a problem with cider/emacs having difficult jumping between the two; but now they're in separate dirs, and I'm much happier

seancorfield07:12:55

I would ask, why would you have tests in the src tree?

seancorfield07:12:30

Pretty much everyone puts their tests in the test tree...

seancorfield07:12:04

After all, when you build production artifacts, you don't want test included.

qqq07:12:30

@seancorfield : because I'm working on hobby projects, and getting C-c p t to work was more important than directory structure at the time (until it started getting overcrowded)

qqq07:12:56

I was going from "no unit testing -> unit testing" not "good practice -> bad practive"

joshjones07:12:19

there's a lesson there somewhere... 😉

sveri08:12:10

I think multiple lessons are waiting in the backlog 😄

qqq08:12:27

The greatest gain is from "no unit tests" to "unit tests" -- anything else is pre mature optimization. 🙂

piotrek09:12:27

Thank you @pesterhazy, that works

futuro16:12:08

Anyone know what clojure.lang.AReference is for or about?

roelof16:12:52

I have now these specs :

; specs for validatimg input to find rhe ids(s/def ::artObject (s/keys :req-un [::objectNumber]))(s/def ::artObjects (s/coll-of ::artObject))(s/def ::body (s/keys :req-un [::artObjects]))(s/def ::response (s/keys :req-un [::body])) 
Is it right I have to make copies of artObjects if I want to check for objectNumber and for example a description

roelof16:12:30

and use a merge to test for both ?

Alex Miller (Clojure team)16:12:55

@futuro it's a base class for reference type implementations

futuro16:12:44

@alexmiller I must admit I'm a little confused by what a reference type is

futuro16:12:04

I see in the source that clojure.lang.ARef extends clojure.lang.AReference, and so does clojure.lang.Namespace, and then c.l.Atom, c.l.Agent, c.l.Ref, and c.l.Var extend c.l.ARef; which at first glance makes me think c.l.AReference is a super-type of just about everything

futuro16:12:14

ah, but a little searching helps me; am I correct in understanding that vars, refs, agents, and atoms are all reference types?

gfredericks16:12:20

a reference type is generally a "pointer" to a single value, and you can use deref to pull the value out

futuro16:12:01

Cool, thank you @gfredericks and @alexmiller 🙂

dpsutton18:12:55

When writing middlewares for nrepl, is there a dynamic var bound to the id of the response I'm working on?

dpsutton18:12:51

I'm registering a handler for writing to java.lang.System/out. Its registered once but the middleware puts the id of the registering request rather than the request it is handling further down

dpsutton18:12:04

I'm actually a little surprised that I can't leave the Id off and let the middlewares further up merge it in if its nil

gfredericks19:12:39

@dpsutton there's a dynamic var with the whole req I think

gfredericks19:12:14

that might be only accessible during eval though

dpsutton19:12:01

CIDER registers the out redirects on id 7

dpsutton19:12:55

and it looks like if you eval (.println (java.lang.System/out) "hi") it has that binding but its bound to id 7

gfredericks19:12:33

nrepl middlewares always give me a headache

dpsutton19:12:09

and its so slow to test

dpsutton19:12:21

as you modify stuff, lein install, and see what happens

gfredericks19:12:08

I think I tested faster than that

gfredericks19:12:26

if you run lein repl out of the project with the middleware you should be able to do it that way

gfredericks19:12:42

still a pain to test, just didn't have to go through maven

qqq19:12:07

I have a file. It has ~ 20 functions. 4 are public. The rest are private. When unit testing, do I only test these 4 functions (because the rest are implementation details) or do I unit test all of them (helps me check bugs when refactoring) ?

dpsutton19:12:33

what do you prefer?

dpsutton19:12:42

do you need to test your private functions?

qqq19:12:06

Last night, I went from s/foo/bar.clj and src/foo/bar_test.clj to a separate "test" directory; so I want to follow best practices.

dpsutton19:12:26

best practice is test what needs to be tested

dpsutton19:12:44

I'm a big fan of not 100% testing coverage but testing the bits that need to be

dpsutton19:12:01

but that's orthogonal to private/public functions

lvh20:12:15

Is there any chance of https://github.com/clojure-emacs/cider/blob/c698df1c905127f190efee3403822b2b09a811c3/doc/indent_spec.md becoming an official clojure thing? I think it’s a good standard, but standards like these are only as good as how much they’re used

qqq20:12:44

I need a way to (1) dump out all function names and (2) for each function, print the number of arguments it takes (or if it's var arg). What libraries / functions should I use to do this?

mingp20:12:16

@qqq Do you mind if I ask, what are you trying to build?

mingp20:12:36

Do you want to operate at the level of source files or loaded namespaces?

qqq20:12:41

@mingp: In haskell, because functions have fixed arity, we can do application without using ()

qqq20:12:52

I would like to write a clojure macro (!! ... ) which does something similar

qqq20:12:19

it looks at its arguments, figures out which ones are functions, and their input arity, then puts () at the right palces [this would ignore var arg functions and functions with multiple arity]

dpsutton20:12:19

@qqq i did something similar in cider-nrepl

qqq20:12:37

@dpsutton: awesome! can you please point me to the github lines? 🙂

dpsutton20:12:57

check out the function zero-arity-callable

dpsutton20:12:09

when refreshing a repl, it used to invoke functions that you set up for before and after

dpsutton20:12:15

but only if they were zero arity

dpsutton20:12:28

but this prevented functions where the args where entirely optional

qqq20:12:35

(:argslist (meta func)) looks like the key

qqq20:12:21

is the :arglists field of meta something that (1) you setup yourself or (2) something clojure does for you?

dpsutton20:12:43

i believe that the defun form does it

dpsutton20:12:07

so if you define a func with a (def func (fn [] ...)) it may be missing

dpsutton20:12:17

not sure but i have seen some forms without it

qqq20:12:48

(defn foo [a b] [a b]) (meta foo) is returning 'nil' for me

qqq20:12:45

(meta #'foo) <-- shows it now

neupsh20:12:19

is there a way to force correct method dispatch on a java method in clojure? basically, if i do Paths.get("/tmp") works in java, but (Paths/get "/tmp") does not work in clojure. Here Paths` is java.nio.file.Paths. https://docs.oracle.com/javase/8/docs/api/java/nio/file/Paths.html

neupsh20:12:56

I get the following error:

bbloom20:12:19

@nux java varargs are a compiler illusion

bbloom20:12:30

there are two overloads: (string, []string) and (uri)

neupsh20:12:44

sorry, this is the exception: java.lang.ClassCastException: Cannot cast java.lang.String to java.net.URI

bbloom20:12:59

yeah, you need to explicitly pass an empty array

bbloom20:12:02

or maybe nil works too

neupsh20:12:28

@bbloom nil did not work, let me try with empty array

bbloom20:12:55

this works: (java.nio.file.Paths/get "x" (make-array String 0))

qqq21:12:23

using ns-interms, I have gotten a kv map of "symbol" -> "var object for symbol" for namespaces I care about. From this, how do I get the corresponding source of the symbol?

bbloom21:12:27

@qqq try (source source)

qqq21:12:53

@bbloom: is that available in general, or do I need a ruynning repl?

qqq21:12:58

that seems to be from the repl namespace

bbloom21:12:23

sure, so (use ‘clojure.repl) if your repl doesn’t already

qqq21:12:53

1. source is returhing "source not found" even though the repl can see the var. 2. This doesn't seem to be how spectrum https://github.com/arohner/spectrum/tree/master/src/spectrum is doing it

qqq21:12:59

any idea how spectrum is getting the source to analyze ?

bbloom21:12:20

try a fully qualified name

qqq21:12:32

I used a full qualified name; let me show full interaction

qqq21:12:05

user> [g.h0.fl/foo (source g.h0.fl/foo)] Source not found [#function[g.h0.fl/foo] nil]

qqq21:12:15

so it sees the symbol, but can't get the source

bbloom21:12:39

source works by looking on the file system

bbloom21:12:57

so a file that the source looks up has to be evaluated via require or whatever it does that adds the :file metadata to the var

bbloom21:12:21

try (meta #‘nc) on your var, does it have :file, :line, :column?

qqq21:12:31

(keys (meta #'g.h0.fl/foo)) (:arglists :line :column :file :name :ns)

qqq21:12:46

and the values there are non-nil

bbloom21:12:51

are the values sensible?

qqq21:12:59

yes, they're correct

qqq21:12:12

the :file name exists

qqq21:12:19

and is the file that contains the code of the module

bbloom21:12:29

well then i’m not quite sure - you’re going to have to dig 🙂

olslash21:12:42

can anyone think of a performant way to query ~250 sqlite file databases that will be read from more-or-less equally ?i'm using a third party data source that happens to be structured in individual DBs... i've considered writing a script to merge them into postgress or something but it complicates the process of updating the resource dbs individually.

olslash21:12:51

right now i've got a map of :id => db connection (using conman for a connection pool) and it works, but i think the overhead is probably huge (havent figured out how to measure it yet)

nikki21:12:44

I guess one nice thing about loop is you can write recursive anonymous functions easily without having to use combinators

qqq21:12:03

one thing I wish I could do with loop is (loop [obj] .... (modify obj) .... (modify obj) .... (recur))

qqq21:12:14

instead of having to "compute the entire new obj all at once at the place of recur"

qqq21:12:11

I was hoping "haskell state monad"

olslash21:12:13

ive run into that before and figured i wasnt thinking functionally enough

olslash21:12:21

didnt really know how to fix it though

qqq21:12:47

sometimes, it's imperative though, like I have one part which is: increment counter add element ot raw data store update indexes

qqq21:12:03

and clojure forces mt to compute all 3 at one spot

gfredericks22:12:26

(with-local-vars [v1 "foo" v2 :bar] ...)

mingp22:12:59

@gfredericks How does using a local var compare with using a volatile or a plain atom? When is each preferable?

gfredericks23:12:48

I've never seen anybody use a local var in my life, so I have no idea.

qqq23:12:44

I think, but am not certain, that local vars are "cheaper" than atoms, because atoms are concurrency safe, and local vars should only be used in one thread?

roelof23:12:02

Happy 2017

qqq23:12:32

I am pprint on a large data structure. Is there a way to tell pprint to only print 20 lines?} I could possibly use (subs (with-out-str (pprint ...))) ... but then it has the problem that I end up printing it as a string

qqq23:12:39

whereas, I'd want the \n to be actual newlines

seancorfield23:12:27

@qqq You can use *print-level* and *print-length* to control that

seancorfield23:12:39

for example (binding [*print-level* 5 *print-length* 5 ] (clojure.pprint/pprint {:a 1 :b {:c 2 :d (range 20) :e 3} :f 4}))

seancorfield23:12:52

(adjust both values to see the effects)

qqq23:12:13

@seancorfield: print-level is even more better

seancorfield23:12:51

(binding [*print-level* 3 *print-length* 2 ] (clojure.pprint/pprint {:a 1 :b {:c 2 :d (range 20) :e 3} :f 4}))
user=> {:a 1, :b {#, #, ...}, …}

qqq23:12:44

clojure.tools.analyzer.jvm is the most verbose output I have yet to see

richiardiandrea23:12:40

[xpost] Is there a way in honeysql or pure clojure.jdbc to cast a Postgres parameter? I receive :

PSQLException ERROR: column "personal" is of type jsonb but expression is of type character varying
  Hint: You will need to rewrite or cast the expression.
  Position: 66  org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse (QueryExecutorImpl.java:2182)

richiardiandrea23:12:04

I am passing a parameter as jsonb