workspace
stringclasses
4 values
channel
stringclasses
4 values
text
stringlengths
1
3.93k
ts
stringlengths
26
26
user
stringlengths
2
11
clojurians
clojure
I don’t know of a better option
2017-12-07T17:56:53.000037
Margaret
clojurians
clojure
<@Margaret> ```((fn [m ks] (into (empty m) (select-keys m ks))) (sorted-map 3 "3" 1 "1" 2 "2") [1 3])``` returns ```{1 "1", 3 "3"}```, which 1.) still includes the keys (easy fix) and 2.) isn't in the same order as the original sorted-map
2017-12-07T17:58:43.000274
Raul
clojurians
clojure
except maybe rewriting select-keys to use `(empty map)`
2017-12-07T17:58:54.000055
Margaret
clojurians
clojure
wait, that sorted map literal is not the same order as the sorted-map
2017-12-07T17:59:22.000376
Margaret
clojurians
clojure
actually no, that's fine
2017-12-07T17:59:29.000134
Raul
clojurians
clojure
maybe you want something different, like an insertion ordered map
2017-12-07T17:59:31.000210
Margaret
clojurians
clojure
sorted-map doesn't work like I thought it did :smile:
2017-12-07T17:59:34.000336
Raul
clojurians
clojure
haha - there’s a lib with an insertion-sorted map out there
2017-12-07T17:59:46.000494
Margaret
clojurians
clojure
eh...this is small enough, I'm just going to use a vector and iterate over values
2017-12-07T17:59:48.000455
Raul
clojurians
clojure
(current size of vector: 2, expected size ~5)
2017-12-07T18:00:05.000124
Raul
clojurians
clojure
performance isn't really an issue on that size
2017-12-07T18:00:13.000205
Raul
clojurians
clojure
also if you use the insertion-ordered one, you can just iterate and filter for the keys you care about since seq would return them in order
2017-12-07T18:00:20.000103
Margaret
clojurians
clojure
thanks for the input, <@Margaret>
2017-12-07T18:00:26.000181
Raul
clojurians
clojure
np
2017-12-07T18:00:30.000338
Margaret
clojurians
clojure
if I need to overwrite "print" and "equality", is deftype the right way to go ?
2017-12-07T18:46:05.000352
Berry
clojurians
clojure
by print do you mean print-method (what pr uses) or toString (what str and print use)
2017-12-07T18:47:13.000230
Margaret
clojurians
clojure
I wasn't even aware of that distinction.
2017-12-07T18:47:29.000072
Berry
clojurians
clojure
print-method is a multimethod that decides how pr / prn show things - this is used for return values in the repl and is meant to be readable by the reader if possible
2017-12-07T18:47:56.000130
Margaret
clojurians
clojure
this can be extended at any time (like any multimethod)
2017-12-07T18:48:11.000352
Margaret
clojurians
clojure
toString is a method on object that is used for str and print / println, and it isn’t meant to be clojure readable, and needs to be defined when defining your class as a method on Object
2017-12-07T18:48:45.000029
Margaret
clojurians
clojure
IIRC while defrecord does give you a nice toString you can override it…
2017-12-07T18:49:03.000334
Margaret
clojurians
clojure
the XY problem is: I need t define toString/equality on int-array / float-array
2017-12-07T18:49:41.000010
Berry
clojurians
clojure
<@Berry> ```(ins)user=&gt; (defrecord Foo [] Object (toString [this] "hello")) user.Foo (ins)user=&gt; (Foo.) #user.Foo{} (ins)user=&gt; (str (Foo.)) "hello"```
2017-12-07T18:49:47.000047
Margaret
clojurians
clojure
oh - well you can’t change arrays but I guess you could make a thing that acts like one with new toString - I think you might need a more powerful tool than deftype for that since deftype can’t do concrete inheretance
2017-12-07T18:50:36.000149
Margaret
clojurians
clojure
so you’d likely need proxy, or gen-class, or some java code
2017-12-07T18:50:48.000122
Margaret
clojurians
clojure
I was thinking of creating an object, via deftype, which has one field, the array.
2017-12-07T18:51:07.000137
Berry
clojurians
clojure
Then, I define print/equality on the deftype ... okay, so technically I'm not overwriting int-array float-array
2017-12-07T18:51:23.000188
Berry
clojurians
clojure
but you can’t make other people think it’s an array, is the problem
2017-12-07T18:51:24.000090
Margaret
clojurians
clojure
I'm defining a wrapper around them.
2017-12-07T18:51:33.000083
Berry
clojurians
clojure
right - if you dont’ need to fool a consumer about the type, then that should work OK I think
2017-12-07T18:51:55.000355
Margaret
clojurians
clojure
the trick might be methods on array you can’t extend
2017-12-07T18:52:17.000133
Margaret
clojurians
clojure
or things like aget / aset etc. which… dunno how you would make those work without extending the class itself
2017-12-07T18:52:42.000164
Margaret
clojurians
clojure
I'm writing an interpreter, like poor-man's matlab/numpy. These "virtual rrays" can only be accessed by interfaces I define.
2017-12-07T18:52:45.000273
Berry
clojurians
clojure
oh neverm ind you should be fine then
2017-12-07T18:52:56.000296
Margaret
clojurians
clojure
I think we are loudly agreeing. :slightly_smiling_face:
2017-12-07T18:53:01.000040
Berry
clojurians
clojure
Uh. Switching to HoneySQL. Can't find how add RETURNING into query builder. Can anyone help?
2017-12-07T19:48:11.000184
Marcos
clojurians
clojure
Found! <https://github.com/nilenso/honeysql-postgres>
2017-12-07T19:54:09.000239
Marcos
clojurians
clojure
To scan a whole file system (collecting information about file sizes), is recursively applying `.listFiles` the fastest option available to me? I couldn't immediately work out whether it was based on nio2 which seems to be the lowest level option available in Java? Anecdotally my approach seems orders of magnitude slower than, for example, DaisyDisk (I am on a Mac) which appears (although maybe they have some way of deferring the fetching of individual file information for a folder?) to be able to gather the same information in under 30s. -- digging around in the Java I see `java.nio.file.Files#walkFileTree` and I don't think `.listFiles` is using that so I guess I should start digging there.
2017-12-08T06:50:05.000149
Kayleigh
clojurians
clojure
Hello all, how do I convert this? ``` SSHClient ssh = new SSHClient(); ssh.addHostKeyVerifier( new HostKeyVerifier() { @Override public boolean verify(String s, int i, PublicKey publicKey) { return true; } }); ```
2017-12-08T07:21:43.000374
Lois
clojurians
clojure
<@Lois> `reify` for `new HostKeyVerifier() { ` which seems the only non-straightforward part
2017-12-08T07:29:40.000281
Kristy
clojurians
clojure
how can I do `traverse` in clojure? So I have an array of `[1 2 3 4]` and I’d like to call let’s say `get-user` function, which accepts a user ID and does an http call and then I want to end up with an array of results basically
2017-12-08T07:34:34.000062
Tameka
clojurians
clojure
if I use map, will that hold the computation that happens afterwards, before everything is resolved?
2017-12-08T07:35:06.000124
Tameka
clojurians
clojure
<@Tameka> yes, as long as you realize the computation
2017-12-08T07:42:34.000038
Jami
clojurians
clojure
you could even use <https://clojuredocs.org/clojure.core/pmap>
2017-12-08T07:42:43.000466
Jami
clojurians
clojure
and use doall to ensure you produce the side effect <https://clojuredocs.org/clojure.core/doall>
2017-12-08T07:43:09.000159
Jami
clojurians
clojure
gotcha, thank you!
2017-12-08T07:43:34.000194
Tameka
clojurians
clojure
that’s cool :smile:
2017-12-08T07:45:23.000400
Tameka
clojurians
clojure
Hrmm... even using `hara.io.file.list` which seems to be nio based is glacially slow. I guess apps like DaisyDisk must be using OSX specific apis not available to Java.
2017-12-08T07:55:35.000120
Kayleigh
clojurians
clojure
trying to wrap my head around fully qualified keywords, would the following be a valid way to refer to a spec in another namespace: ``` (ns foo (:require [clojure.spec :as s])) (s/def ::layout-string ...) (ns bar (:require [clojure.spec :as s])) (s/fdef parse-layout-string :args :foo/layout-string ...) ``` ? (I ask since I’m getting an interesting ‘Call to clojure.core/ns did not conform to spec’ error)
2017-12-08T07:58:10.000164
Joette
clojurians
clojure
yes, "::" resolves to your current namespace
2017-12-08T08:00:06.000233
Jami
clojurians
clojure
but you should put (:require foo) in ns bar
2017-12-08T08:00:40.000002
Jami
clojurians
clojure
<@Jami> thank you!
2017-12-08T08:07:17.000003
Joette
clojurians
clojure
<@Jami> seems my error was an incompatibility in my dependency chain with clojure 1.9…could be I’m a bit thick here, but I don’t always find those spec error messages entirely easy to grok
2017-12-08T08:17:42.000221
Joette
clojurians
clojure
they certainly take some getting used to
2017-12-08T08:20:00.000435
Cecilia
clojurians
clojure
there is this <https://github.com/bhb/expound>
2017-12-08T08:20:52.000333
Cecilia
clojurians
clojure
you can try to make them more readable with <https://github.com/bhb/expound>
2017-12-08T08:20:54.000537
Jami
clojurians
clojure
<@Cecilia> <@Jami> thanks for the pointer, I’ll take a look at expound
2017-12-08T08:25:18.000225
Joette
clojurians
clojure
problem is this was the clojure compiler complaining about code I didn’t write. Not sure it would be possible to force the clojure internal spec conform calls to use expound…
2017-12-08T08:26:40.000216
Joette
clojurians
clojure
yes it is
2017-12-08T08:26:57.000187
Cecilia
clojurians
clojure
<https://github.com/bhb/expound#explain-out>
2017-12-08T08:27:23.000135
Cecilia
clojurians
clojure
if that is set then spec uses expound to do it’s error printing
2017-12-08T08:28:08.000242
Cecilia
clojurians
clojure
would it be possible to inject this early enough in the build process so that when clojure checks my transitive dependencies, it would use expound/printer? (I’m using leiningen)
2017-12-08T08:29:33.000321
Joette
clojurians
clojure
not sure, haven’t tried it. But you can execute arbitrary code within Leiningen. The problem is though, that if the exception actually does truly happen during dependency resolution then it is kinda too early since spec itself is a dependency
2017-12-08T08:30:51.000427
Cecilia
clojurians
clojure
and so is expound
2017-12-08T08:30:57.000117
Cecilia
clojurians
clojure
I would be super surprised the problem would surface during dependency resolution though
2017-12-08T08:31:23.000148
Cecilia
clojurians
clojure
after dependencies you can execute code via leiningen `:injections`, see example here <https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L182>
2017-12-08T08:32:02.000474
Cecilia
clojurians
clojure
argh
2017-12-08T08:32:06.000204
Cecilia
clojurians
clojure
You could put it in user.clj - thats loaded pretty early
2017-12-08T08:32:08.000541
Sonny
clojurians
clojure
user.clj is another option, that comes later than `:injections` but if that is enough then it would be preferrable.
2017-12-08T08:33:18.000345
Cecilia
clojurians
clojure
I think one of my dependencies was not built to work with clojure 1.9 and fails a few checks when it is, I have solved the issue by upping the dependency to a version which is built for 1.9 so this is somewhat academic for the purposes of my immediate issue, but interesting nevertheless
2017-12-08T08:33:19.000197
Joette
clojurians
clojure
right, well that would not break during dependency resolution
2017-12-08T08:33:43.000309
Cecilia
clojurians
clojure
thank you both for the pointers
2017-12-08T08:33:44.000418
Joette
clojurians
clojure
but more when it gets loaded
2017-12-08T08:33:49.000187
Cecilia
clojurians
clojure
so, you have plenty of time to hook expound as spec error printer
2017-12-08T08:34:09.000172
Cecilia
clojurians
clojure
and here my clojure newbieness shines through a bit. Would not the dependencies be loaded on “first refer” or something, i.e. probably before the code in core.clj etc is executed?
2017-12-08T08:35:10.000056
Joette
clojurians
clojure
if your code is not AOT compiled then dependencies etc are loaded when you require them
2017-12-08T08:35:43.000293
Cecilia
clojurians
clojure
so, if you add the expound hook into user.clj - which is the very first thing Clojure loads - and there only refer spec and expound then you will get that code executed before another piece of code gets executed which will try to require the offending library
2017-12-08T08:36:45.000148
Cecilia
clojurians
clojure
which would normally be in the ns block at the top, so the error printer hooking would have to happen before that at least
2017-12-08T08:36:46.000002
Joette
clojurians
clojure
<@Cecilia> ok, thank you again!
2017-12-08T08:37:41.000074
Joette
clojurians
clojure
np, the dynamic nature of Clojure is really powerful, it has a slight drawback of relatively high startup time but in general it’s benefits far outweigh the downsides
2017-12-08T08:38:16.000001
Cecilia
clojurians
clojure
you pretty much cannot do stuff like that in most of the languages
2017-12-08T08:38:47.000300
Cecilia
clojurians
clojure
It is ok to seek feedback for a library idea here? Its a rather big idea so before releasing anything I and investing too much I want to make sure its not totally wrong! edit: <https://www.reddit.com/r/Clojure/comments/7if66b/objection_another_component_alternative_is_this_a/> gh: <https://github.com/riverford/objection>
2017-12-08T09:13:17.000121
Elmira
clojurians
clojure
why wouldn’t it be? :slightly_smiling_face:
2017-12-08T09:14:14.000684
Cecilia
clojurians
clojure
tell us about your idea and we’ll evaluate it
2017-12-08T09:14:28.000057
Cecilia
clojurians
clojure
I might not have time right now but someone will
2017-12-08T09:14:34.000628
Cecilia
clojurians
clojure
I've attached a reddit thread/github link :slightly_smiling_face:
2017-12-08T09:15:30.000296
Elmira
clojurians
clojure
Any comments would be greatly appreciated, just so I know whether to invest in it - I have lots of open-source work that I want to do and want to get a feel for whether its worth the risk on this one (as it seems very risky)
2017-12-08T09:16:56.000666
Elmira
clojurians
clojure
ok, I read the github page
2017-12-08T09:17:40.000339
Cecilia
clojurians
clojure
really doesn’t look that different from mount to me
2017-12-08T09:18:14.000367
Cecilia
clojurians
clojure
for example, the “lazy construction instead of explicit single start! fn.” is not strictly totally true, you can specify which components you want started with mount when you call it’s start!
2017-12-08T09:18:45.000624
Cecilia
clojurians
clojure
I've started a thread.
2017-12-08T09:19:32.000364
Elmira
clojurians
clojure
so, I would say that would look great if there were no mount available, since it is however I do not see any real value I would get out of that
2017-12-08T09:20:09.000708
Cecilia
clojurians
clojure
<@Cecilia> could you paste your stuff here? :slightly_smiling_face:
2017-12-08T09:20:24.000225
Elmira
clojurians
clojure
ah, sorry
2017-12-08T09:20:37.000276
Cecilia
clojurians
clojure
Empperi [4:17 PM] ok, I read the github page [4:18] really doesn’t look that different from mount to me [4:18] for example, the “lazy construction instead of explicit single start! fn.” is not strictly totally true, you can specify which components you want started with mount when you call it’s start! [4:20] so, I would say that would look great if there were no mount available, since it is however I do not see any real value I would get out of that
2017-12-08T09:20:50.000064
Cecilia
clojurians
clojure
so, I wouldn’t say “don’t do it” but as it is now it doesn’t look compelling enough to me to justify a new library
2017-12-08T09:21:23.000316
Cecilia
clojurians
clojure
I would prefer seeing some PRs in mount to improve it if you find it lacking
2017-12-08T09:21:37.000464
Cecilia
clojurians
clojure
but, I got to go and cannot give you any more relevant feedback. Do not kill your idea based on just what I said :slightly_smiling_face:
2017-12-08T09:22:49.000390
Cecilia
clojurians
clojure
I do not use mount, I have looked at it in the past - in fact a lot of this came out of a lack of satisfaction with mount/integrant/component for certain kinds of system. I do appreciate 'yet another component/mount/bla' alternative, and one of the main reasons why I am apprehensive. I'll adjust the readme a bit to try and help demonstrate why its different, and where the value prop is of this over the others. Thanks for taking the time to give it a look :slightly_smiling_face:
2017-12-08T09:24:55.000390
Elmira
clojurians
clojure
looks like clojure 1.9 is out :)
2017-12-08T09:30:37.000004
Kareen