Fork me on GitHub
#clojure
<
2017-07-31
>
kaosko00:07:24

@camdez - one more, do you know to handle rounding the numbers in transit-cljs? I don't seem to be able to supply a custom handler for "Number"

camdez01:07:37

@kaosko I’m not certain but I believe Number is a superclass of a variety of types. I think you’ll have to identify what the underlying class is and add a WriteHandler for that.

kaosko02:07:57

@camdez just answering my own question - all numbers are just Numbers in js. have to specify {js/Number (NumberHandler.)}} to override and must use (tag [_ v] "i"), if you specify empty tag, it'll go to an infinite loop

camdez02:07:48

@kaosko Oh, I didn’t notice you’d said “cljs”. But I’m glad to hear you got it worked out!

roklenarcic10:07:36

is there some way to use Spring with Clojure

donyorm10:07:45

I'm making a program that allows plugins to be added to it. I'm thinking of creating a launcher that runs the program with the plugins included in the classpath, does this seem reasonable? It seems like the absolute best way to do this would be to write a custom class loader, but I'm not sure I have the experience to write one well (as suggested by @hiredman)

cristian.sandu10:07:17

hello everyone. I am looking around for a way to implement this: https://medium.com/react-native-training/deep-linking-your-react-native-app-d87c39a1ad5e in clojure with re-natal… has anyone tried this?

bcbradley12:07:50

Does anyone know of a wavefront or collada file loader for clojure? I basically want to load a geometry definition file as a clojure data structure. I might have to make my own library for that, but it doesn't hurt to ask.

juhoteperi13:07:29

@bcbradley I've used assimp with C++, but readme mentions there being Java bindings also: https://github.com/assimp/assimp

mhjort14:07:54

No experience with assimp Java bindings. However, assimp seems to have the best support for loading different 3D models. If you want Open Source library that is. At least that used to be the case about year ago.

ghadi15:07:13

anyone have a good method to use tools.deps to include the current working directory besides running it once then appending:

echo -n ":${PWD}/src" >> .cpcache/default/default.cp

mbertheau16:07:54

Can I write this more concisely? (let [x (group-by some-pred some-coll) matches (x true) non-matches (x false)] ...)

dpsutton16:07:02

first thought is to use map destructuring where you name the key and the var name it should destructure to

bronsa16:07:05

(let [{matches true non-matches false} (group-by ..)] ..)

mbertheau16:07:46

Ah, I had the map destructuring backwards. Thanks!

the-kenny16:07:33

I rarely see this destructuring syntax in the projects I work on. We always use {:keys [key-a, key-b]} (which I personally find much more readable)

bronsa16:07:53

it is more readable but it's not equivalent in power

mbertheau16:07:09

That wouldn't work with boolean keys true and false I think.

the-kenny16:07:52

yeah, it likely wouldn't. I'm just mentioning this for the generic case. Imo this line above is already too hard to grasp when skimming through code.

bfabry16:07:19

yeah it wouldn't, :keys syntax only works with keyword keys. {binding key} lets you use any type of key

the-kenny16:07:49

Note that there's also :syms and :strs. Still wouldn't work in this case, though

bfabry16:07:06

I agree that it would be a bit crazy to use {binding key} over {:keys} if you have a map with keywords, it's just less readable. but sometimes (at boundaries) you don't

bronsa16:07:30

it's not that crazy if you want to rename keys

bronsa16:07:46

{foo-name :name} to avoid shadowing name, for example

bfabry16:07:49

I've literally never seen :syms or :strs used in the wild and I would have to look it up 🙂 probably still better

Garrett Hopper16:07:44

Is there a better way to do (filter identity coll)? I'm needing to do it to interpose " " between args before (apply str ...).

Garrett Hopper16:07:29

Current:

(defn class [& classes]
  (apply str (interpose " " (filter identity classes))))

bfabry16:07:58

imo (remove nil? classes) is more readable

Garrett Hopper16:07:44

Yeah, I'd thought about that. I don't see any reason false would be passed into this, but I'd like to support it if it is.

bfabry16:07:29

then (filter some? classes) is slightly more readable than identity

bfabry16:07:46

oh wait that doesn'tsupport false either

Garrett Hopper16:07:59

That's alright 🙂

sundarj16:07:14

(filter boolean classes)?

Garrett Hopper16:07:06

That's good :thumbsup: @sundarj

bfabry16:07:49

ruby has a function, compact that does this. but honestly that name is really a bit opaque

noisesmith17:07:18

filter identity is the normal way to do this

didibus17:07:26

Question: Is there a way I can have a polymorphic dispatch where the dispatch function is itself open for extension? Some kind of open cond like construct?

potetm17:07:52

multimethods?

noisesmith17:07:00

@didibus there’s no rule that says a dog can’t play basketball your multimethod dispatch can’t be a multimethod

potetm17:07:05

:disappear:

seancorfield17:07:07

@bfabry (some? false) => true so you could (filter some? classes) right?

didibus17:07:41

Hum, can it, I'll try it out.

seancorfield17:07:54

Or am I misunderstanding what @ghopper is trying to do?

seancorfield17:07:16

(what does "support false" mean?)

jeff.terrell17:07:45

@ghopper - If coll is returned by map you might be able to use keep instead of map. Can't quite remember how keep handles false vs. nils though so that'd be worth confirming.

noisesmith17:07:16

=> (keep identity [false nil 1])
(false 1)

bfabry17:07:25

@seancorfield I took it to mean they wanted to filter out both nil and false (which (filter identity ...) does)

Garrett Hopper17:07:30

@seancorfield Support false meaning it would filter false and nil out. Just like identity does. So some? should work.

noisesmith17:07:43

no, some? passes false through

noisesmith17:07:56

just use identity if that’s the semantics you want

seancorfield17:07:36

Right, use some? if you only want to filter nil but keep false.

seancorfield17:07:01

"support false" sounded like you wanted to allow it through and identity wasn't doing that for you...

Garrett Hopper17:07:06

I hadn't heard of keep before, but as @noisesmith pointed out, it doesn't handle false as intended. (filter identity coll) works perfectly fine. :thumbsup:

seancorfield17:07:09

Words. What do words mean? 🙂

Garrett Hopper17:07:33

@seancorfield Not what I indend them to mean normally. 😉

noisesmith17:07:53

(defmulti DWIM identity)

leonoel17:07:05

is there a convenient way to disable implicit binding conveyance ?

noisesmith17:07:13

@leonoel In jvm clojure the simplest thing is to start a thread via interop instead of using one of clojure’s utility functions for creating threads (.start (Thread. (fn [] (println "hello"))))

noisesmith17:07:48

any zero arg clojure function is a valid argument to the thread constructor, and will be the thing the thread does when started

noisesmith17:07:13

this method of running a function only sees global bindings, and won’t convey any local dynamic bindings

leonoel17:07:51

ok so I guess it is somehow against the language to try to use dynamic vars as thread locals ?

noisesmith17:07:50

well - they are thread local, they just get conveyed to other threads if you use things like future or send-off

noisesmith17:07:55

or core.async stuff

noisesmith17:07:39

I thought what you were asking for was how to avoid the inheritance of those thread local bindings

noisesmith17:07:50

(or to create a new context without them at least)

leonoel17:07:12

what I'm trying to achieve is a mechanism for detecting if a function call has been made out of a synchronous context

noisesmith17:07:31

what is a “synchronous context” - synchronous with what?

noisesmith17:07:00

that is, I can easily start code inside core.async go that is synchronous within itself but async with the caller - and it’s easy to end up with an app where almost everything is “async” if you go far enough up the call stack, but in practice nearly all of the logic is sync

leonoel17:07:08

it's hard to find a minimal example, but basically I create event queues, I have functions that must be "bound" to a single event queue, so I need a way to test if I'm currently running this queue, if so it's ok to run synchronously, else you have to post an event

leonoel17:07:38

a threadlocal is a good way to achieve this, but if I use dynamic vars, the event queue context will be conveyed

noisesmith17:07:56

sounds like instead of avoiding binding conveyance, you could just rely on it, and set a dynamic var *in-queue* to true and get the right behavior?

noisesmith17:07:51

oh, so children of the queue shouldn’t inherit that context, only the queue worker itself should have it?

leonoel17:07:49

yes, if I use future while I'm the queue, I don't want the thread running the future to believe that it's still in the queue

noisesmith17:07:51

you could create a global set at the ns level with the queue Thread instances in it, and check if (Thread/currentThread) returns something in that set

noisesmith17:07:07

that’s cheap and the logic is simple

weavejester17:07:41

Does anyone have an invite to Screenhero they could throw my way?

ghadi17:07:11

slack has now integrated screensharing into slack directly

ghadi17:07:30

in the /call stuff ...

weavejester17:07:50

Huh, I’ll try it out.

weavejester17:07:56

Hm, looks like it’s paid teams only. Not useful in this case.

weavejester13:08:04

Oh, thanks! But I’m afraid I already have an invite. Thank you anyway.

leonoel17:07:59

it's similar to using a threadlocal, isn't it ?

noisesmith17:07:37

(pardon, misread)

noisesmith17:07:15

kind of - but the emphasis is different - instead of setting a threadLocal in each thread, you add each thread to a container that keeps track of them

noisesmith17:07:31

one is global, explicit, and visible, the other is hidden and implicit

leonoel17:07:03

@noisesmith ok I will think about that - thanks anyway, but I'm still a bit confused about the dynamic var philosophy

noisesmith17:07:48

it’s meant for things that would be visible to this thread and all the ones it creates

noisesmith17:07:22

eg. think about how with-out-str works - it overrides the destination for printing for the caller and all child threads

leonoel17:07:51

the implicit aspect looks a bit dangerous to me, and the only benefit I see is to save a few characters when you write your functions

didibus17:07:14

Question: How would I extend a protocol to all array types? I seem to only be able to do it for a specific array, like say "[Ljava.lang.Object". But I want "[L?"

hiredman17:07:16

there is no such thing

didibus17:07:53

😞 Its strange that "[Ljava.lang.Object" doesn't even work for subtypes of Object. It only works if I have actual array of Objects

hiredman17:07:57

that is how array types work on the jvm

hiredman17:07:37

array types don't have that kind of type relation

hiredman17:07:43

if A is an array of X and B is an array of Y, and Y is a subtype of X, B is not a subtype of A

didibus17:07:36

I'm not convinced, since instanceof can tell the relation

bronsa17:07:08

@hiredman java array are covariant, it's generics that aren't

bfabry18:07:15

yeah I might be missing something but I get no compile error

11326-storage:tmp bfabry$ cat > Foo.java
public class Foo {
  public Object[] fooey;
  public Foo() {
    fooey = new String[10];
  }
}
11326-storage:tmp bfabry$ javac Foo.java
11326-storage:tmp bfabry$

didibus18:07:25

=> IllegalArgumentException No implementation of method: :t of protocol: #'special.eagerize-test/Table found for class: [Ljava.lang.String;

didibus18:07:46

My solution was to extend java.lang.Object, and do: (when (instance? (Class/forName "[Ljava.lang.Object;") <implementation-for-arrays>)

didibus18:07:09

(when (instance? (Class/forName "[Ljava.lang.Object;") this) <implementation-for-arrays>)

didibus18:07:07

Question: What is in clojurescript the type I need to extend to cover all types? Equivalent to java.lang.Object say?

didibus18:07:08

Ok, clojurescript has default for that, awesome. I actually wished Clojure had that too.

plins21:07:52

hello everyone, how im supposed to create a spec where all keys are optional but at least one of the specified keys should be present?

(s/def ::my-spec (s/and (help-plz??)(s/keys :opt-un [::a ::b])))
(s/valid? ::my-spec {} => false
(s/valid? ::my-spec {:a 1}) => true
(s/valid? ::my-spec {:b 1}) => true
(s/valid? ::my-spec {:a 1 :b 1}) => true
(s/valid? ::my-spec {:A1 :B 1}) => true

mpenet21:07:24

You can use :req-un [(or ::foo ::bar)]

bfabry21:07:43

I totally forgot about that syntax

mpenet21:07:24

It's one thing I love in spec

bfabry21:07:26

@plins (some-fn :a :b) not good enough?

plins21:07:03

some-fn is actually a function? i presumed i was supposed to fill in the gaps >.< feel so dumb right now

bfabry21:07:51

oh I'm sorry yeah I could see how you'd read it that way. but no, some-fn is a higher order function that takes a list of predicate functions and returns a single predicate function that is the logical or of all of them

plins21:07:00

makes sense now!

bfabry21:07:44

you could also do #(some % [:a :b])

bfabry21:07:23

^ relies on maps acting as functions

timgilbert21:07:30

Say, is there a form of (cond) that will bind the result value of the predicate expressions? Like

(cond
  (my-pred x)
  (do-something (my-pred x)))
Where (my-pred x) returns either nil or a value I want to use?

timgilbert21:07:53

...but I'd like something like:

(cond-let
  ([res (my-pred x)]
   (do-something res)))

dpsutton21:07:32

it's a cond-let macro

timgilbert21:07:23

Thanks @dpsutton, I'll check that out. Nothing built-in I'm missing then, I take it?

dpsutton21:07:51

not as far as i know

timgilbert21:07:34

Cool, thanks. Looks like that macro exists verbatim in a lot of libraries... https://crossclj.info/clojure/cond-let.html

dpsutton21:07:29

the exact same? I guess its just one of those clojure archetypes

the2bears22:07:03

I am curious as to where people are storing simple jdbc queries? I have a set of ~8 or so queries, all plain queries without any parameters. Do you use a "config" type file?

cddr22:07:46

Stick 'em in the resources directory of your project then you can retrieve them by slurping the return value of ( "foo.sql")

the2bears23:07:39

@cddr - yes, certainly in the resources directory. I was just wondering if there was a preferred file format but a .sql file makes the intent of the file very apparent, which is good.