workspace
stringclasses
4 values
channel
stringclasses
4 values
text
stringlengths
1
3.93k
ts
stringlengths
26
26
user
stringlengths
2
11
clojurians
clojure
<@Timmy> however, if you're adding values to lots of keys, perhaps two generic functions would work together better? `(def vec-conj (fnil conj []))` and a function to `update-keys` for updating many keys with the same fn.
2017-12-05T09:38:36.000005
Jodie
clojurians
clojure
I see, thanks!!
2017-12-05T09:42:36.000231
James
clojurians
clojure
just `vec-conj` has tidied things up plenty. Cheers man!
2017-12-05T09:43:01.000587
Timmy
clojurians
clojure
``` user=&gt; (def vec-conj (fnil conj [])) #'user/vec-conj user=&gt; (defn update-keys [m ks &amp; args] #_=&gt; (reduce (fn [m k] (apply update m k args)) m ks)) #'user/update-keys user=&gt; (update-keys {:k nil :v [1 2] :c (list :a)} [:new :k :v :c] vec-conj :new-val) {:k [:new-val], :v [1 2 :new-val], :c (:new-val :a), :new [:new-val]} ``` As I was toying around :slightly_smiling_face:
2017-12-05T09:43:18.000219
Jodie
clojurians
clojure
Is `first` lazy?
2017-12-05T10:55:41.000855
Blanch
clojurians
clojure
nope
2017-12-05T10:58:01.000616
Xavier
clojurians
clojure
```(let [s (lazy-seq (println "Called!") (cons :foo nil))] (first s)) Called! =&gt; :foo ```
2017-12-05T11:00:19.000025
Xavier
clojurians
clojure
How could `first` be lazy?
2017-12-05T11:09:15.000889
Sonny
clojurians
clojure
`fst :: (a, b) -&gt; a` :slightly_smiling_face:
2017-12-05T11:12:57.000117
Willow
clojurians
clojure
well, Clojure has eager evaluation semantics so it’s not lazy in that sense
2017-12-05T11:14:30.000200
Sonny
clojurians
clojure
agreed. fst in haskell isn't lazy, _haskell_ is lazy
2017-12-05T11:15:04.000162
Willow
clojurians
clojure
it just lays around all day waiting for something to happen, psh
2017-12-05T11:16:03.000356
Sonny
clojurians
clojure
so do I. it's a wonder haskell and I never got on
2017-12-05T11:25:18.000303
Myles
clojurians
clojure
you have to sufficiently motivate it. otherwise it just prints `nah` and dies in constant time
2017-12-05T11:26:25.000068
Willow
clojurians
clojure
<@Myles> you could also try <http://eta-lang.org/> if it's needed to run it on JVM
2017-12-05T11:27:11.000042
Heriberto
clojurians
clojure
Is `trampoline`'s performance good? There's an JavaScript &lt;https://taylodl.wordpress.com/2013/06/07/functional-javascript-tail-call-optimization-and-trampolines/|article&gt; (Clojure `trampoline` implementation seems to be similar) and it says: &gt;The trampoline implementation has essentially the same number of function invocations as the traditional recursive implementation. A TCO would eliminate these function invocations. &gt;We’ve traded the work of creating stack frames with creating function bindings. Both operations consume time and memory. TCO doesn’t create function references due to its modifying the function implementation in place to transform the recursive implementation to a loop. So it seems that `trampoline` isn't a substitute for TCO.
2017-12-05T11:48:29.000271
Heriberto
clojurians
clojure
while it is right that the number of function invocation stays the same, the big difference is that those stack frames don't exist in memory all at once but they exist one at a time
2017-12-05T11:50:03.000447
Kareen
clojurians
clojure
nobody claimed that trampoline is a substitute for TCO
2017-12-05T11:50:42.000446
Kareen
clojurians
clojure
I see. Thank you, <@Kareen>!
2017-12-05T11:51:09.000163
Heriberto
clojurians
clojure
trampoline is a workaround for a problem that is also solved by TCO
2017-12-05T11:51:13.000341
Kareen
clojurians
clojure
isn't trampoline usually how TCO is implemented under the hood, as well?
2017-12-05T12:19:20.000273
Willow
clojurians
clojure
no
2017-12-05T12:20:36.000654
Kareen
clojurians
clojure
general TCO transforms function call and return into jumps
2017-12-05T12:23:11.000202
Kareen
clojurians
clojure
<@Willow> it's interesting, on the x86 the place the code jumps to on a return is simply a pointer on the stack. So you can implement other models that patch up that value to do stuff like TCO or continuation passing. Sadly this is also fairly insecure, so the JVM abstracts all that away, and doesn't give you control over the return address.
2017-12-05T12:50:25.000250
Sandy
clojurians
clojure
<http://repository.readscheme.org/ftp/papers/ai-lab-pubs/AIM-443.pdf>
2017-12-05T12:54:45.000217
Rebeca
clojurians
clojure
heh, and these days, with branch prediction, procedure calls are practically free :smile:
2017-12-05T13:05:06.000201
Sandy
clojurians
clojure
sure, but the compilation strategy in the paper generates code where calls are just a jump without a pushed return address unless required (looks like cps or a precursor), of course it predates worrying about the x86 calling conventions, because people were still arguing about if subroutines were a good idea
2017-12-05T13:10:30.000291
Rebeca
clojurians
clojure
practically free... at the cost of huge silicon wastage
2017-12-05T13:34:22.000803
Guillermo
clojurians
clojure
or higher power envelope
2017-12-05T13:34:40.000175
Guillermo
clojurians
clojure
<http://www.iro.umontreal.ca/~feeley/papers/SaleilFeeleyECOOP17.pdf>
2017-12-05T13:36:55.000155
Guillermo
clojurians
clojure
&gt; Interprocedural Specialization of Higher-Order Dynamic Languages Without Static Analysis This looks like a promising avenue for optimizing functional languages like Clojure
2017-12-05T13:37:23.000490
Guillermo
clojurians
clojure
is there an easy way to downgrade lein?
2017-12-05T14:58:22.000175
Willow
clojurians
clojure
well apparently `lein updade 2.7.1` will upgrade to a specific version
2017-12-05T14:59:03.000527
Willow
clojurians
clojure
same works for downgrading
2017-12-05T15:17:09.000343
Shira
clojurians
clojure
i.e. `lein update 2.5.0` will up/downgrade to that version
2017-12-05T15:17:22.000724
Shira
clojurians
clojure
Just curious, why the downgrade?
2017-12-05T15:18:52.000696
Guillermo
clojurians
clojure
we have a plugin not working with 2.8.1, last known is 2.7.1
2017-12-05T15:25:46.000073
Willow
clojurians
clojure
slothconfig i think is the culprit
2017-12-05T15:26:21.000265
Willow
clojurians
clojure
Does anyone recommend a library for writing isomorphic data conversions/bijections? Basically being able to write one implementation to go from `type a -&gt; type b`, and getting `type b -&gt; type a` "for free"
2017-12-05T17:48:35.000506
Lonna
clojurians
clojure
is that even possible? it sounds kinda like <https://github.com/nathanmarz/specter>
2017-12-05T17:53:43.000241
Jonas
clojurians
clojure
where you can zoom in on part of a datastructure, perform transformations locally, and then zoom out
2017-12-05T17:54:11.000148
Jonas
clojurians
clojure
<@Lonna>, clojure prefers data (hashmaps vectors) instead of types, so I'm not sure this applies?
2017-12-05T17:57:37.000466
Sandy
clojurians
clojure
there are a lot of libraries that do things like define some base conversion functions, then create a graph of all the types, then use the graph and base conversion functions to generate the rest of the conversion functions
2017-12-05T18:00:21.000148
Rebeca
clojurians
clojure
<https://github.com/dm3/clojure.java-time/blob/master/src/java_time/graph.clj> is an example of something like that
2017-12-05T18:11:07.000178
Rebeca
clojurians
clojure
<@Jonas> possibly, and specter seems nice, but not quite it <@Sandy> Clojure doesn't emphasize types, but they're still implicitly there. You'll see something like `(defn a-&gt;b [a] ...)`, which (by convention) is a typecast from a to b <@Rebeca> I saw <https://github.com/twitter/bijection> which seems to fit. Know of any others?
2017-12-05T18:11:29.000522
Lonna
clojurians
clojure
<@Lonna> but what types are you trying to convert. If a and b are records, then (map-&gt;b a) is automatic
2017-12-05T18:12:46.000266
Sandy
clojurians
clojure
as is (map-&gt;a b)
2017-12-05T18:12:52.000257
Sandy
clojurians
clojure
I have two different representations of the same thing. I want to write a single set of rules that goes from a to b, and get the reverse function (b to a) automatically
2017-12-05T18:14:45.000004
Lonna
clojurians
clojure
That's what I'm getting at, why do you have two representations of the same thing? Why not store them in one format?
2017-12-05T18:15:17.000190
Sandy
clojurians
clojure
Keep the data in hashmaps, or even records, and then stuff just works.
2017-12-05T18:15:32.000431
Sandy
clojurians
clojure
also - it really depends on what data transformation you are talking about, it’s provable that you can’t write a general function for such conversions so there must be other constraints implied here
2017-12-05T18:16:06.000003
Margaret
clojurians
clojure
"two representations of the same thing"
2017-12-05T18:16:28.000029
Willow
clojurians
clojure
Because the things in question are events, and the "business event" looks different from the event that's sent out to the external event service. There's no magic solution of "use the same format" here
2017-12-05T18:16:30.000027
Lonna
clojurians
clojure
sounds good here
2017-12-05T18:16:31.000208
Willow
clojurians
clojure
that sounds like a data modeling problem. Chances are that with namespaced keywords and hashmaps your required transformations would be quite minimal
2017-12-05T18:17:37.000336
Sandy
clojurians
clojure
{:event/timestamp ...} can exist in any hashmap that's an event with a timestamp
2017-12-05T18:18:00.000318
Sandy
clojurians
clojure
and if you have {:service.event/timestamp ...} then its a question if you really need to discriminate between a service event timestamp and a ui event timestamp
2017-12-05T18:18:41.000246
Sandy
clojurians
clojure
what does an "event" look like quest? I think i follow you and i see what you are trying to do
2017-12-05T18:19:24.000361
Willow
clojurians
clojure
I'm saying all this because the last time I needed a library like this I was in a C# app where a good 40% of all our code was nothing more than type conversions. Moving to Clojure removed the need for that.
2017-12-05T18:19:37.000303
Sandy
clojurians
clojure
sounds like there's a notion of "add a customer", and this app calls it `create-customer` and some other apps call it `customer-create`
2017-12-05T18:20:04.000435
Willow
clojurians
clojure
and you just want to translate back and forth?
2017-12-05T18:20:12.000375
Willow
clojurians
clojure
OK -- for instance, our business event contains various fields. ``` {:foo-id "abcde"} ``` The external service we publish them to supports "custom fields" via a `facts` map. ``` {:facts {:foo-id "abcde"}} ```
2017-12-05T18:20:56.000460
Lonna
clojurians
clojure
All I want a way to specify this transformation that will work "forwards and backwards"
2017-12-05T18:21:40.000377
Lonna
clojurians
clojure
I can handroll this easy enough, just figured there was a "declarative" way to specify these transformations. I notice someone made <https://github.com/gfredericks/schema-bijections> which is the same idea
2017-12-05T18:24:07.000130
Lonna
clojurians
clojure
it’s not a standard or built in thing - that lib is the closest thing I’ve seen
2017-12-05T18:25:03.000342
Margaret
clojurians
clojure
fair enough. I can kinda imagine a way to do this via transducers if they each one in the chain was "reversible", but never seen that either
2017-12-05T18:25:40.000192
Lonna
clojurians
clojure
I misunderstood, thought you wanted to describe a one way transition and have the reverse defined automatically
2017-12-05T18:25:53.000189
Margaret
clojurians
clojure
clojure has no way to define, declare, or detect reversibility
2017-12-05T18:26:07.000185
Margaret
clojurians
clojure
yeah -- no way you could do this "automatically" without also having definitions of what (and how) things can be reversed
2017-12-05T18:27:04.000276
Lonna
clojurians
clojure
though if you limit yourself to purely isomorphic translations (and your library understands that), then it could generate the reverse for you
2017-12-05T18:27:42.000022
Lonna
clojurians
clojure
I wouldn’t be surprised if the haskell or idris compiler did such things, but clojure’s compiler doesn’t even aim to be clever like that
2017-12-05T18:27:47.000360
Margaret
clojurians
clojure
that’s true - you could make your own declarative language for transforms
2017-12-05T18:28:02.000057
Margaret
clojurians
clojure
might be a fun thing to try in eg. core.logic
2017-12-05T18:28:35.000438
Margaret
clojurians
clojure
hmm... that's true, and finding out how to mesh this with specs would be an interesting (and relevant) challenge for me. good idea :slightly_smiling_face:
2017-12-05T18:29:05.000256
Lonna
clojurians
clojure
having known gfredericks for a while, my instinct when something he wrote comes up is that either I’m on track of something very clever and useful or something very clever and … perverse
2017-12-05T18:30:34.000079
Margaret
clojurians
clojure
(known online that is, just hung out with him at a couple conferences)
2017-12-05T18:30:56.000183
Margaret
clojurians
clojure
eg. <https://github.com/gfredericks/seventy-one>
2017-12-05T18:31:39.000165
Margaret
clojurians
clojure
<https://github.com/gfredericks/quinedb>
2017-12-05T18:31:56.000385
Margaret
clojurians
clojure
haha - I’ll stop now
2017-12-05T18:32:02.000008
Margaret
clojurians
clojure
I get what you mean by perverse :grin:
2017-12-05T18:32:36.000175
Lonna
clojurians
clojure
there’s a lot of overlap with what you’re describing and specter. basically you have a bunch of reversible operations. the library has a specific use case in mind (manipulating immutable nested data structures), but you could in theory have navigators that are just reversible operations (i think)
2017-12-05T18:35:06.000437
Jonas
clojurians
clojure
i’m not saying it’s a good fit for what you’re doing, but you may be able find/borrow inpirations
2017-12-05T18:36:11.000136
Jonas
clojurians
clojure
didn't even consider that. Specter does have _a lot_ of nice stuff going on under the hood, will also take a look at that
2017-12-05T18:36:55.000110
Lonna
clojurians
clojure
it’s clear that you could use `select` and a path to go from one type to another
2017-12-05T18:37:31.000227
Jonas
clojurians
clojure
not sure if you could use `transform` to automatically do the reverse given the same path
2017-12-05T18:37:49.000176
Jonas
clojurians
clojure
(a path being a list of navigators)
2017-12-05T18:38:35.000014
Jonas
clojurians
clojure
which you would be repurposing as reversible operations
2017-12-05T18:39:01.000314
Jonas
clojurians
clojure
don't know enough about Specter -- but worst case, as long as there's a set of operations, I can manually denote which ones are reversible (and how). whether that ends up being an extension of specter, core.logic, or a different library entirely... we'll see
2017-12-05T18:43:53.000402
Lonna
clojurians
clojure
seems cool
2017-12-05T18:44:36.000220
Jonas
clojurians
clojure
hello again, all. been a while. I am back in a ruby shop, where I get quizzical looks when I say that a handful of functions can do what OOP does, but simpler, easier, and faster. how best to illuminate my co-workers?
2017-12-05T19:08:23.000198
Sarita
clojurians
clojure
I’ve found that I’ve grown more convincing as I’ve become better at explaining my thoughts. developing the right vocabulary for describing design tradeoffs has been a huge help. ie. rather than just saying something is better or worse, being able to describe design tradeoffs in terms of coupling, cohesion, or other code attributes. also being able to explain how a design makes tradeoffs in terms of quantifiable metrics can also help (eg. how a design makes tradeoffs in terms of latency vs throughput)
2017-12-05T19:18:26.000279
Jonas
clojurians
clojure
I think the first book that helped me be more descriptive about how to describe the tradeoffs of different designs was code complete
2017-12-05T19:19:05.000166
Jonas
clojurians
clojure
with respect to ruby, rich hickey did give the key note at a rails conf, <https://www.youtube.com/watch?v=rI8tNMsozo0>
2017-12-05T19:20:59.000451
Jonas
clojurians
clojure
<http://aroma.vn/web/wp-content/uploads/2016/11/code-complete-2nd-edition-v413hav.pdf>
2017-12-05T19:22:39.000111
Jonas
clojurians
clojure
here’s a great list of different code attributes (with definitions!)
2017-12-05T19:24:32.000154
Jonas
clojurians
clojure
Any quick little way to convert `[["a" "b"] ["c" "d"] ["e" "f"]]` to `[["a" "c" "e"] ["b" "d" "f"]]`?
2017-12-05T19:25:29.000113
Keesha
clojurians
clojure
<@Keesha> (map vector c) ```&gt; (apply map vector [["a" "b"] ["c" "d"] ["e" "f"]]) (["a" "c" "e"] ["b" "d" "f"])``` (apply here because it was all in one vec)
2017-12-05T19:25:40.000013
Margaret
clojurians
clojure
That’s the one. Thanks guys
2017-12-05T19:27:38.000253
Keesha
clojurians
clojure
`(def transpose (partial apply map vector))` is a remarkable little chunk of code (I learned it on IRC I forget who from) (edit: better name)
2017-12-05T19:28:58.000186
Margaret
clojurians
clojure
Oh thats neat. Thank you!
2017-12-05T19:30:46.000057
Keesha