workspace
stringclasses
4 values
channel
stringclasses
4 values
text
stringlengths
1
3.93k
ts
stringlengths
26
26
user
stringlengths
2
11
clojurians
clojure
and ```clojure.core/namespace ([x]) Returns the namespace String of a symbol or keyword, or nil if not present.```
2017-12-06T16:37:37.000059
Daniell
clojurians
clojure
They are consistent about what they called "name" and what they call "namespace".
2017-12-06T16:37:58.000404
Daniell
clojurians
clojure
If I `partition` over a sequence, and the 'n' I'm using is larger than the size of the sequence, partition returns an empty list. ``` (partition 100 (range 10)) => () ``` I can see how that's important if you're expecting your groups to be a fixed size, but is there a similar function that returns any remainders?
2017-12-06T17:00:51.000708
Kristan
clojurians
clojure
I wanted the return to be: ``` ((0 1 2 3 4 5 6 7 8 9)) ```
2017-12-06T17:01:11.000355
Kristan
clojurians
clojure
Ah, there's actually a comment from Rich Hickey on this: <https://groups.google.com/forum/#!msg/clojure/ZK0zRhAjeJ8/4sM2tDz4_iAJ> "The current logic pushes the onus on the producer of the data, where it belongs, rather then the consumer." I'll go with that.
2017-12-06T17:06:35.000402
Kristan
clojurians
clojure
see `partition-all`
2017-12-06T17:07:19.000069
Guillermo
clojurians
clojure
there are other arguments to `partition` that can help, too.
2017-12-06T17:07:41.000079
Guillermo
clojurians
clojure
<@Kristan> you can get the behavior you want by providing an empty padding collection. You need to specify a step size to satisfy the arity, so it'd be `(partition 100 100 [] (range 10))`
2017-12-06T17:15:19.000380
Lavenia
clojurians
clojure
Is there an idiomatic/performant way to select a random element from a hash-set? (rand-nth (seq set-value)) doesn't feel right.
2017-12-06T17:15:55.000526
Wilda
clojurians
clojure
Hi all. I want to write function to get data with `(require '[korma.core :as kc])`. ```(defn get-message* ([query] (kc/select message (kc/where query))) ([query &amp; fields] (kc/select message (kc/where query) (apply kc/fields fields))))``` It looks ok, but. select is a macro and it want to use it like this: ```(kc/select message (kc/where query) (kc/fields field1 field2))``` And as result it breaks here: `(apply kc/fields fields)`. How to deal with this?
2017-12-06T17:18:07.000246
Marcos
clojurians
clojure
to generate a call to a macro, you usually need to create another macro
2017-12-06T17:19:01.000274
Margaret
clojurians
clojure
Yeah, I thought about macro-apply. Is there one? I dunno how to write it
2017-12-06T17:19:27.000059
Marcos
clojurians
clojure
``` `(kc/select ~message (kc/where ~query) (kc/fields ~@fields)) ```
2017-12-06T17:19:53.000138
Margaret
clojurians
clojure
ah
2017-12-06T17:19:59.000380
Marcos
clojurians
clojure
no, but there is ~@
2017-12-06T17:20:00.000258
Margaret
clojurians
clojure
Yeah, I forgot about ~@.
2017-12-06T17:20:13.000263
Marcos
clojurians
clojure
Cool! Thanks, <@Margaret>
2017-12-06T17:20:24.000002
Marcos
clojurians
clojure
just remember that to do a multi-arity macro you need to make a macro that expands to another call to the macro
2017-12-06T17:20:46.000210
Margaret
clojurians
clojure
you can’t just call it the normal way
2017-12-06T17:20:51.000082
Margaret
clojurians
clojure
Okay, thanks
2017-12-06T17:21:06.000653
Marcos
clojurians
clojure
oh, looking again, I probably did `message` wrong there
2017-12-06T17:21:58.000435
Margaret
clojurians
clojure
Yeah, I noticed
2017-12-06T17:22:14.000072
Marcos
clojurians
clojure
Also. How I should to eval this? Call eval?
2017-12-06T17:22:28.000158
Marcos
clojurians
clojure
oh - right - to do this with runtime generated data…
2017-12-06T17:22:51.000240
Margaret
clojurians
clojure
```(defn get-message* ([query] (kc/select message (kc/where query))) ([query &amp; fields] (eval `(kc/select message (kc/where ~query) (kc/fields ~@fields))))) ```
2017-12-06T17:23:30.000012
Marcos
clojurians
clojure
ideally you can find a version of this that doesn’t require macros on runtime generated collections, but if that’s the best option all things considered yeah you end up with eval
2017-12-06T17:23:38.000431
Margaret
clojurians
clojure
I also can create raw sql query without macros.. Ill think about this later
2017-12-06T17:24:20.000283
Marcos
clojurians
clojure
Is there an idiomatic/performant way to select a random element from a hash-set? (rand-nth (seq set-value)) doesn't seem to perform very well. It is about the same as shuffling a seq and taking the first element.
2017-12-06T17:36:13.000444
Wilda
clojurians
clojure
It feels like there should be a much faster way of doing this.
2017-12-06T17:38:08.000040
Wilda
clojurians
clojure
<@Marcos> Another option is to stop using Korma (it's no longer maintained, is it?) and use HoneySQL instead with `clojure.java.jdbc` -- HoneySQL is designed to let you compose query fragments together.
2017-12-06T17:42:56.000320
Daniell
clojurians
clojure
<@Wilda> a hash set doesn't implement anything with an O(1) access guarantee, just O(n), so I don't think there's anyway to access those elements except sequentially...
2017-12-06T17:45:29.000363
Daniell
clojurians
clojure
I see, thanks!
2017-12-06T17:46:34.000558
Wilda
clojurians
clojure
<@Daniell>, I like korma for table relationship definitions and as result some features like "with". Is there something like korma what is still maintaining ?
2017-12-06T17:52:17.000233
Marcos
clojurians
clojure
<@Marcos> I think that whole entity-relationship thing kinda flies in the face of Clojure's raw data approach... I suspect there are ORM-like alternatives to Korma but I doubt any of them are well-maintained: it's just not really idiomatic (IMO).
2017-12-06T17:54:05.000134
Daniell
clojurians
clojure
hm.. Okay. <@Daniell>, honeySQL only library what I should consider to use?
2017-12-06T17:55:06.000135
Marcos
clojurians
clojure
<https://github.com/jkk/honeysql>
2017-12-06T18:00:06.000584
Daniell
clojurians
clojure
(and then `org.clojure/java.jdbc` for executing the queries -- which you're almost certainly already using under the hood via Korma)
2017-12-06T18:00:53.000008
Daniell
clojurians
clojure
yeah, I use jdbc in korma. Very old version of jdbc (0.3.7 instead of last 0.7.3)
2017-12-06T18:02:22.000257
Marcos
clojurians
clojure
Lots of changes since then -- another reason to avoid Korma!
2017-12-06T18:02:47.000426
Daniell
clojurians
clojure
0.7.3 brings reducible queries, for example!
2017-12-06T18:03:21.000241
Daniell
clojurians
clojure
uhh, I already want to switch to HoneySQL
2017-12-06T18:03:42.000268
Marcos
clojurians
clojure
Okay. Another question, It is still related to korma
2017-12-06T18:03:59.000083
Marcos
clojurians
clojure
```$ psql testdb testdb=&gt; \d message Table "public.message" Column | Type | Collation | Nullable | Default -----------------+--------------------------+-----------+----------+------------------------------------- /* snipped */ time_sent | timestamp with time zone | | not null | /* snipped */ $ lein repl project.scratch=&gt; (require '[korma.core :as kc] #_=&gt; '[clj-time.core :as t] #_=&gt; '[clj-time.coerce :as tc]) nil project.scratch=&gt; (let [timestamp (tc/to-sql-date (t/now)) #_=&gt; msg {:time_sent timestamp, /* snipped */}] #_=&gt; (println "Trying to insert: " (:time_sent msg)) #_=&gt; (println "What is inserted: " (:time_sent (kc/insert message (kc/values msg))))) Trying to insert: #inst "2017-12-06T22:43:58.074-00:00" What is inserted: #inst "2017-12-06T22:00:00.000000000-00:00" nil```
2017-12-06T18:04:07.000523
Marcos
clojurians
clojure
Im using postgresql. Im trying to insert timestamp into table, but I get time without minutes and seconds. Why?
2017-12-06T18:05:27.000231
Marcos
clojurians
clojure
Could it be Korma?
2017-12-06T18:05:33.000478
Marcos
clojurians
clojure
I am immediately suspicious of /* snipped */
2017-12-06T18:07:50.000237
Rebeca
clojurians
clojure
Okay, Ill return snipped now
2017-12-06T18:08:21.000164
Marcos
clojurians
clojure
I suspect because you're converting it to a SQL Date rather than a timestamp and the JDBC conversion strips the time portion (modulo the TZ adjustment)
2017-12-06T18:08:31.000317
Daniell
clojurians
clojure
or where the timestamp is being generated and written
2017-12-06T18:08:35.000035
Rebeca
clojurians
clojure
<@Rebeca> Timestamp generating in let.
2017-12-06T18:09:14.000194
Marcos
clojurians
clojure
yeah, but where is it written to the database?
2017-12-06T18:09:31.000293
Rebeca
clojurians
clojure
<@Rebeca> last println
2017-12-06T18:10:01.000085
Marcos
clojurians
clojure
`(kc/insert ...`
2017-12-06T18:10:09.000229
Marcos
clojurians
clojure
and what does kv/values return?
2017-12-06T18:10:40.000345
Rebeca
clojurians
clojure
kc
2017-12-06T18:10:43.000106
Rebeca
clojurians
clojure
Hm, ill chek it now
2017-12-06T18:10:54.000518
Marcos
clojurians
clojure
<@Rebeca> ```project.scratch=&gt; (kc/values message {:account_id 3, :dest_account_id 4, :time_sent (tc/to-sql-date (t/now)), :content "hello"}) {:table "message", :name "message", :pk :id, :db nil, :transforms (), :prepares (), :fields [], :rel {"account" #object[clojure.lang.Delay 0x47aa5b5b {:status :pending, :val nil}], "chat" #object[clojure.lang.Delay 0x2b69f1d1 {:status :pending, :val nil}]}, :values [{:account_id 3, :dest_account_id 4, :time_sent #inst "2017-12-06T23:11:24.302-00:00", :content "hello"}]}```
2017-12-06T18:11:56.000121
Marcos
clojurians
clojure
It contains not stripped time
2017-12-06T18:12:12.000425
Marcos
clojurians
clojure
<@Daniell>, how can I check this?
2017-12-06T18:13:04.000172
Marcos
clojurians
clojure
<https://github.com/clj-time/clj-time/blob/master/src/clj_time/coerce.clj#L54>
2017-12-06T18:14:14.000340
Rebeca
clojurians
clojure
<@Daniell> is right of course
2017-12-06T18:14:24.000362
Rebeca
clojurians
clojure
<https://github.com/clj-time/clj-time/blob/master/src/clj_time/coerce.clj#L85-L89>
2017-12-06T18:14:48.000241
Rebeca
clojurians
clojure
FWIW <@Marcos> We use `tc/to-date` rather than `tc/to-sql-date` in our code.
2017-12-06T18:14:55.000153
Daniell
clojurians
clojure
<https://docs.oracle.com/javase/7/docs/api/java/sql/Date.html>
2017-12-06T18:15:16.000536
Rebeca
clojurians
clojure
<@Daniell> with to-date it throws an error ```project.scratch=&gt; (kc/insert message (kc/values {:account_id 3, :dest_account_id 4, :time_sent (tc/to-date (t/now)), :content "hello"}))``` `PSQLException Can't infer the SQL type to use for an instance of java.util.Date. Use setObject() with an explicit Types value to specify the type to use. org.postgresql.jdbc2.AbstractJdbc2Statement.setObject (AbstractJdbc2Statement.java:1934)`
2017-12-06T18:16:38.000456
Marcos
clojurians
clojure
(but then we have our app servers and DB servers all set to UTC and our MySQL DB configured to run in UTC as well -- pretty much the only sane setup!)
2017-12-06T18:16:53.000198
Daniell
clojurians
clojure
Seriously? The PostgreSQL JDBC driver can't convert from a Java Date to a timestamp with time zone? Wow...
2017-12-06T18:17:28.000085
Daniell
clojurians
clojure
=-(
2017-12-06T18:17:44.000273
Marcos
clojurians
clojure
Then try `tc/to-sql-time` which will produce a `java.sql.Timestamp` instead...
2017-12-06T18:18:16.000490
Daniell
clojurians
clojure
Hurray. this works. _btw, it was very dumb to confuse with to-sql-date and to-sql-time_
2017-12-06T18:20:47.000090
Marcos
clojurians
clojure
thx <@Daniell> and <@Rebeca>
2017-12-06T18:20:58.000221
Marcos
clojurians
clojure
Nah, not dumb. Java's various dates and date/times are ... peculiar and annoying.
2017-12-06T18:21:42.000246
Daniell
clojurians
clojure
<@Wilda> If you knew in advance that you wanted to generate random elements from the _same_ set many times, you could improve performance by creating a vector of the set elements one time, then calling rand-nth on that vector many times. That doesn't improve performance if you only want to do it once per set, though.
2017-12-06T19:49:45.000104
Micha
clojurians
clojure
I send message lost yesterday:cry:. I’m beginner and I just start use idea tool, thanks for your help, I will learn it.
2017-12-06T21:13:58.000081
Lisabeth
clojurians
clojure
Is there going to be a state of Clojure survey this year?
2017-12-06T21:57:42.000124
Shira
clojurians
clojure
Yeah, we may slip into the new year. Kind of focused on 1.9
2017-12-06T22:54:08.000048
Sonny
clojurians
clojure
`(swap! some-atom func)` suppose func decides to throw an exception (i.e. it can't do the update), what is the proper way to signal this ?
2017-12-07T00:46:33.000046
Berry
clojurians
clojure
<@Berry> throw the exception
2017-12-07T05:48:41.000261
Beulah
clojurians
clojure
i'm using an agent to queue tasks, and want to wait on the task to complete, what is the proper way to do this?
2017-12-07T07:28:34.000272
Jena
clojurians
clojure
i'm now using this: ```(let [p (promise) a (agent 0) task-fn (fn [x] (let [new-val (inc x)] (deliver p new-val) new-val))] (send a task-fn) @p)```
2017-12-07T07:29:57.000422
Jena
clojurians
clojure
but this delivers the promise before the task fn completes, so it not completely waterproof
2017-12-07T07:31:37.000365
Jena
clojurians
clojure
in theory, it could happen that `(not= @p @a)`
2017-12-07T07:32:09.000108
Jena
clojurians
clojure
<@Jena> you can't make waterproof assumptions on an agent deref
2017-12-07T07:36:37.000114
Rosia
clojurians
clojure
<@Jena> could you use core.async for this case ?
2017-12-07T07:37:27.000307
Jami
clojurians
clojure
Use `await` or `await-for`
2017-12-07T08:00:09.000402
Sonny
clojurians
clojure
i only need to wait until the submitted task completes, with await it would wait for all dispatched tasks
2017-12-07T08:13:54.000284
Jena
clojurians
clojure
maybe an agent is not the right solution for my problem, i'll think about it
2017-12-07T08:14:44.000387
Jena
clojurians
clojure
Found a solution: i can add watch, and pass the delayed deliver to it. As watches are called after the state is updated, this ensures that once the promise is delivered, the task has updated the agent state
2017-12-07T08:31:02.000021
Jena
clojurians
clojure
```(let [p (promise) a (add-watch (agent {:x 0}) :force-deliver (fn [_ _ _ new-val] (force (:delayed-deliver new-val)))) task-fn (fn [{:keys [x]}] (let [new-val (inc x)] {:x new-val :delayed-deliver (delay (deliver p new-val))}))] (send a task-fn) [@p @a])```
2017-12-07T08:31:16.000107
Jena
clojurians
clojure
that doesn't guaranteed the state has not been updated by another task meanwhile
2017-12-07T08:35:03.000114
Rosia
clojurians
clojure
true, but thats acceptable for my use case
2017-12-07T08:35:12.000361
Jena
clojurians
clojure
I would like some advice about bytecode generation. I have a java class with a public primitive int field I want to assign with `set!`, however I can't manage to get rid of intermediate boxing no matter what I hint. The decompiled bytecode for assignment is always something like : ``` ((TheClass)the_instance).the_field = RT.intCast((Number)Numbers.num(value)); ``` This looks suboptimal, I'm not sure the runtime is clever enough to bypass this kind of stuff. Am I missing something ?
2017-12-07T09:57:37.000130
Rosia
clojurians
clojure
you'll have to show us the code that's producing that
2017-12-07T10:10:21.000734
Kareen
clojurians
clojure
<@Marcos> you probably solved it already, but take a look at `select*` instead of `select`, it returns a query object that can easily be composed later
2017-12-07T10:13:46.000431
Xavier
clojurians
clojure
and then realized with `exec`
2017-12-07T10:14:05.000257
Xavier
clojurians
clojure
```(select tbl (where conditions) (fields ...))``` ```(-&gt; (select* tbl) (where conditions) (fields ...)) ```
2017-12-07T10:15:00.000157
Xavier
clojurians
clojure
you can put parts of queries in functions ``` (defn where-thing-active [query] (where query ({:expires [&gt; (sqlfn :now)] :deleted [= nil]}))) ``` and then compose them easily like ```(-&gt; (my-base-select) (where {:user_id user-id}) (cond-&gt; only-active? where-thing-active type (where {:type (-&gt; type name upper-case)})) exec))```
2017-12-07T10:17:38.000317
Xavier
clojurians
clojure
<@Xavier>, thanks!
2017-12-07T10:17:55.000501
Marcos
clojurians
clojure
here is a minimal example <https://gist.github.com/leonoel/b7e8e4b93e7d14fcbdd3fbdac4921223>
2017-12-07T10:32:46.000595
Rosia
clojurians
clojure
use unchecked-inc-int
2017-12-07T10:35:23.000410
Kareen