Fork me on GitHub
#clojure
<
2018-04-05
>
qqq02:04:56

1. I have an existing java application. 2. I have launched a nrepl from it via (clojure.tools.nrepl.server/start-server ...) 3. I can connect to this repl via "boot repl --client --port 5555" 4. I want to run (require 'foo.bar) 5. how do I set the src path that clojure searches for foo/bar.clj in ?

seancorfield02:04:09

@qqq Are you trying to load code that is external to the application?

qqq02:04:47

https://clojuredocs.org/clojure.core/add-classpath <-- this is marked as Deprecated. What is it replaced with ?

qqq02:04:59

@seancorfield: I want to specify a path ~/blahblah-src/ then I want (require 'foo.bar) to search ~/blahblah-src/foo/bar.clj

seancorfield02:04:19

You could load files via their file system path using load-file...

seancorfield02:04:52

Unless you start the application with a classpath that includes your src directory perhaps?

seancorfield02:04:21

Deprecated just means "there are better ways". It doesn't mean "removed".

dpsutton03:04:54

is there a split-when function? split-with is almost never what i want

sundarj05:04:24

depending on what you want, partition-by may be the ticket

danielcompton05:04:24

Does anyone know of a bounded prn function? I want to print an arbitrarily large data structure, but only the first (say) 100 characters of it, and don't want to spend the CPU to print the whole thing out.

sundarj05:04:18

=> (binding [*print-length* 10] (prn (range 100)))
(0 1 2 3 4 5 6 7 8 9 ...)
nil

sundarj05:04:25

there's also *print-level*

danielcompton05:04:23

I’ll take a look, although I think the nested shape of the data may not work here

sundarj05:04:42

=> (binding [*print-level* 2] (prn {:a {:b {:c 4}}}))
{:a {:b #}}

danielcompton05:04:33

Oh yeah and there could be a single massive string in there too

sundarj05:04:24

ah, I don't know if there's anything for strings

danielcompton18:04:44

Awesome, that looks like what I’m thinking of

ag06:04:12

how do I "continuously" interleave two colls? e.g. if I have:

[:a :b :c] [1 2]
I want to get [:a 1 :a 2 :b 1 :b 2 :c 1 :c 2

schmee06:04:08

@ag use for, (for [x [:a :b :c] y [1 2]] [x y])

ag06:04:14

oh, yeah that works... thanks @schmee

schmee06:04:39

(then do (apply concat ...) on that to get the whole thing)

ag06:04:03

now, this works for me. I'm still curious what if I have more than 2 colls?

schmee06:04:07

you can keep going in the same fashion: (for [x ... y ... z ...] [x y z]) and so on

ag06:04:18

no, I mean if I have "infinitely" many 🙂 then I'm gonna have to use math.combinatorics I guess

dnaeon07:04:37

Which method of function argument validations is considered more idiomatic in Clojure - using :pre and :post checks or perhaps using s/assert in the function body instead? Or perhaps something else instead?

boogie66609:04:38

Hello all, I have a question regarding the "cat" transducer... why does it need to double wrap reduced (i.e. why does it use the preserving-reduced wrapper for rf). Could anyone give me an example of why that's needed?

rauh09:04:17

@boogie666 Do you see how it calls (reduce rrf result input)? If it didn't "double wrap" a (reduced ...) call inside your transduction the reduce would just return the value. And the reduction of the transducer wouldn't honor the reduced.

rauh09:04:14

Basically it makes sure that if the rf function does a reduced call it will propagate to the transduction (which is again a reduce)

boogie66609:04:36

so that means that if the inner reduce stops the whole chain stops.

boogie66609:04:52

the thing is, i can't think of an example where not stoping the whole chain would be a problem

boogie66609:04:05

for that matter, i can't think of an example in which i could stop the whole thing...

boogie66609:04:57

(with cat in composition with something else)

rauh09:04:01

@boogie666 :

(defn cat-wrong
  [rf]
  (fn
    ([] (rf))
    ([result] (rf result))
    ([result input]
     (reduce rf result input))))

(into [] (comp cat-wrong (take-while odd?)) [[1 2] [3]])

rauh09:04:14

Compare with "fixed" cat

boogie66609:04:11

i get it now

rauh09:04:14

The wrong cat just ignored the reduced from take-while and kept going

boogie66609:04:34

i understand

rauh09:04:36

Note, you can't get that to work with (take x) transducer since it will properly guard that (it's more robust)

boogie66609:04:25

that's i could not think of an example 😛 (i was just thinking of regular take)

rauh09:04:02

Yeah take will still work since it keeps internal state. So it would just waste CPU cycles. But still be correct...

djpowell09:04:36

i remember seeing a presentation online about funnel / spc charts in clojure, possibly to do with healthcare? anyone know what im talking about and have a link?

gnejs10:04:29

hi all! I’m looking at a defmethod implementation in clj-http and I don’t fully recognise the form… http://leo-mt-prod-app07.aslan.local:8306/accountretention/admin/metrics?pretty=true — what is that extra arg none-cookie-policy that sits between the dispatch-value and the fn-parameter declaration?

gnejs10:04:50

Is it some sort of syntax for “naming” the defmethod?

Alex Miller (Clojure team)11:04:54

in that case, yes - the “none-cookie-policy” is a function name for the specific defmethod (which you’ll really only see in stack traces typically)

gnejs13:04:57

Thanks Alex! (Yes - the link pointed way wrong.. sorry).

Alex Miller (Clojure team)11:04:47

defmethods technically take the “function tail” which is “all the args you’d pass to fn” which includes the (optional) function name

benzap14:04:24

Anyone here using parinfer-mode in emacs? I'm curious what everyone is using for the parinfer-mode-toggle key, Is it something you use often?

callum14:04:14

@U0670BDCH You might find help in #emacs

benzap14:04:29

sure thing

Wesley Matson14:04:09

And only about thrice an hour, depending on the kinds of changes I'm doing

benzap16:04:25

Interesting, so I guess keeping it on C-c C-p wouldn't be that inefficient

Wesley Matson18:04:06

In my experience, C-c C-p was already bound to something (cider pprint something or another). I added C-' after finding there was no binding with where-is

👍 4
theeternalpulse15:04:50

Why do some clojure functions that take arbitrary arguments provide several signatures to handle a known number of arguments before just taking arbitrary ones and applying the rest of the args to them? Is it just for performance and common case handling? for example https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L6123

tbaldridge15:04:25

@theeternalpulse performance, but also for easier code writing

tbaldridge15:04:54

Often the arity that has & rest at the end calls into the other arities

theeternalpulse15:04:54

I see. I'm often a little thrown off by them, I recognize the pattern but I generally wouldn't write arbitrary args like that, then agian I don't write languages 🙂

tbaldridge15:04:15

@theeternalpulse check out Erlang sometime 😄 They take it to a whole new level ,and use that pattern instead of if statement:

while(L) -> while(L,0). 
while([], Acc) -> Acc;

while([_|T], Acc) ->
   io:fwrite("~w~n",[Acc]), 
   while(T,Acc+1).

4
tbaldridge15:04:25

Not sure that it's better than other methods, just a different way of doing it

mv16:04:07

If I wanted to implement a “clojure lite” on the EVM, purely to learn more about compilers and clojure internals, where should I start? Is there any good reading on how clojure and the JVM play together?

pesterhazy16:04:08

well there's https://github.com/kanaka/mal - not sure if that's what you're looking for

👍 4
mv16:04:36

These look like they are implementations in a language, not in a VM. Does Clojure compile to the JVM or Java first?

the2bears16:04:02

It compiles to bytecode, not Java source if that's what you mean.

lsantanna18:04:21

hey guys, what is the best mongodb client for Clojure?

lsantanna18:04:52

Monger seems the most up2dated one, what do you guys think?

markw19:04:40

ugh i'm really bad at slack sorry

markw19:04:43

so... assuming the coll is an instance of PersitentHashMap, it looks like there is no cons method for that object, but it extends APersistentMap, which has the following code:

Alex Miller (Clojure team)19:04:23

yes, that’s all correct

markw19:04:24

I think this is where cons would be called from

markw19:04:27

for a map

markw19:04:43

where I get lost is where the actually addition to the map happens

markw19:04:03

I just see it pulling out values from the passed argument x but not the joining to the map

markw19:04:15

assoc is only passed the elements of the x arg though right?

markw19:04:29

I'm sure my lack of Java knowledge is causing some confusion

Alex Miller (Clojure team)19:04:08

what you said is correct - what’s confusing about it?

Alex Miller (Clojure team)19:04:36

x in RT.conj is a map entry like [k v] if this is a map

Alex Miller (Clojure team)19:04:51

in PAM.cons() that becomes o

Alex Miller (Clojure team)19:04:13

the key and value parts of o get pulled apart and used to invoke assoc, which returns an updated map

markw19:04:22

the final part is where i got lost

markw19:04:29

i see assoc called with the two arguments

markw19:04:44

i don't see how it's added to original coll (map in this case) since it's only passed the two args from x

Alex Miller (Clojure team)19:04:54

oh, this is an instance method on the map instance

Alex Miller (Clojure team)19:04:07

so you are implicitly “in” the map and calling assoc on it

markw19:04:10

the invocation looks like a function call

markw19:04:17

diff than i'm use to from my limited OO experience in Python

Alex Miller (Clojure team)19:04:19

it is, but it’s call on the current object

Alex Miller (Clojure team)19:04:51

all instance method calls in Java have an implicit first argument which is the instance

markw19:04:04

no self everywhere

Alex Miller (Clojure team)19:04:08

which Java uses for dispatch

Alex Miller (Clojure team)19:04:16

you can get that instance with this in Java

Alex Miller (Clojure team)19:04:30

but you typically don’t need to do that explicitly

markw19:04:45

OK thx for clarifying... btw are these type of questions reasonable here or is that more beginner channel?

markw19:04:06

don't want to litter the thread but this channel is extremely helpful so far

Alex Miller (Clojure team)19:04:18

generally, people in this slack are happy to answer questions anywhere :)

markw19:04:39

thanks alex!

Alex Miller (Clojure team)19:04:19

this could easily be #beginners or #java or even #clojure-dev since you’re looking at internals