workspace
stringclasses
4 values
channel
stringclasses
4 values
text
stringlengths
1
3.93k
ts
stringlengths
26
26
user
stringlengths
2
11
clojurians
clojure
all functions passed to f-> take a single arg (the stack) as input and produces a stack as output
2017-12-08T19:01:06.000182
Berry
clojurians
clojure
<@Berry> right but you could imagine something like `[a b c ^{:argc 2} str]` as way to tell the compiler to take 2 args from the stack when applying str to it.
2017-12-08T19:02:23.000049
Deandrea
clojurians
clojure
(f-&gt; a b c (mod 2 str)), where mod :: int -&gt; func -&gt; func , specifies how many args to take and use
2017-12-08T19:03:13.000070
Berry
clojurians
clojure
oh nice. i like that.
2017-12-08T19:03:40.000183
Deandrea
clojurians
clojure
except instead of calling it mod, we should call it m! or something
2017-12-08T19:03:40.000215
Berry
clojurians
clojure
heh, i sometimes wish clojure had that in core. when mapping over a list of lists (for example) i often want something that takes a number `n` and function `f` and pulls `n` many arguments from each list and applies them to the `f` rather than writing the function that unpacks the arguments by hand. it’s easy to write but i sometimes i wish i didn’t have to. :slightly_smiling_face:
2017-12-08T19:05:23.000150
Deandrea
clojurians
clojure
<@Berry> `ap` might be a nice shorthand there. `[a b c str 2 ap]`
2017-12-08T19:08:20.000144
Deandrea
clojurians
clojure
<@Deandrea>: how does 'str know to delay evaluation?
2017-12-08T19:21:32.000174
Berry
clojurians
clojure
i'm assuming nothing but `ap` applies anything
2017-12-08T19:22:16.000045
Kareen
clojurians
clojure
the model I had in mind was: if you get a constant, you push it, if you get a function, you eval it
2017-12-08T19:23:50.000094
Berry
clojurians
clojure
but in this model, it appears to be "push until you hit ap" ?
2017-12-08T19:24:01.000079
Berry
clojurians
clojure
how would you do HOF then?
2017-12-08T19:24:09.000058
Kareen
clojurians
clojure
can you give me a concrete example you have in mind ?
2017-12-08T19:24:29.000030
Berry
clojurians
clojure
write `(map inc [1 2 3])`
2017-12-08T19:24:41.000063
Kareen
clojurians
clojure
is [1 2 3] a single arg on the stack, or is it a stack of 3 items ?
2017-12-08T19:24:59.000026
Berry
clojurians
clojure
that's clojure
2017-12-08T19:25:09.000139
Kareen
clojurians
clojure
write that in your stack based dialect
2017-12-08T19:25:15.000258
Kareen
clojurians
clojure
if your semantics are "if the top element in my stack is a function, apply it", then you have no way of using a function as a value
2017-12-08T19:25:49.000014
Kareen
clojurians
clojure
I was going to do all function combinators in clojure
2017-12-08T19:26:44.000033
Berry
clojurians
clojure
the model I had in mind for `f-&gt;` is: 1. f-&gt; gets a list of args 2. eval each arg 3. if arg is a constant, change it to a push 4. if it's a function, apply it
2017-12-08T19:27:09.000176
Berry
clojurians
clojure
well good luck, keywords symbols vectors maps sets are functions too
2017-12-08T19:27:47.000072
Kareen
clojurians
clojure
F---
2017-12-08T19:27:59.000202
Berry
clojurians
clojure
@qqq let me get back to you. :wink: I've gotta play with my kids right now. I will be back to meditate on this some more. :smile:
2017-12-08T19:39:30.000039
Deandrea
clojurians
clojure
Hi, I just saw the changelog of Clojure 1.9. Do you know why the deps and cli tools were added to the language ? <https://clojure.org/guides/deps_and_cli>
2017-12-09T01:25:50.000076
Jami
clojurians
clojure
as far as I understand, this is a new improvement on resolving dependencies, but what about building clojure apps ?
2017-12-09T01:26:26.000001
Jami
clojurians
clojure
because clojure.core can't run without the clojure.spec.alpha library that is packaged separately
2017-12-09T01:26:32.000016
Margaret
clojurians
clojure
will it replace or complement lein/boot ?
2017-12-09T01:26:41.000004
Jami
clojurians
clojure
it's not a build tool, it just helps use deps
2017-12-09T01:26:44.000019
Margaret
clojurians
clojure
the goal was that people should be able to run clojure directly using a simple tool from the clojure team - clj is designed for that, and just that
2017-12-09T01:27:21.000046
Margaret
clojurians
clojure
so do you think there will be a need to create a new build tool ?
2017-12-09T01:28:14.000040
Jami
clojurians
clojure
in other language, you usually have a compiler/interpreter and a build tool
2017-12-09T01:28:32.000014
Jami
clojurians
clojure
clj isn't mandatory and isn't a build tool
2017-12-09T01:28:44.000024
Margaret
clojurians
clojure
leiningen and boot are still build tools
2017-12-09T01:28:57.000037
Margaret
clojurians
clojure
it doesn't replace leiningen or boot but there are plans to use it from boot at least
2017-12-09T01:30:18.000022
Margaret
clojurians
clojure
I when I begin using clojure, I was confuse about boot and lein. I didn't know if these tool where the interpreter/compiler
2017-12-09T01:30:23.000005
Jami
clojurians
clojure
that's a common problem
2017-12-09T01:30:32.000025
Margaret
clojurians
clojure
ok, i see the picture
2017-12-09T01:31:00.000040
Jami
clojurians
clojure
the goal is to have: 1) clj as the main interpreter, 2) deps.edn as a format to specify dependencies 3) boot/lein as build tool
2017-12-09T01:31:31.000026
Jami
clojurians
clojure
but at the moment, boot and lein does everything
2017-12-09T01:31:44.000039
Jami
clojurians
clojure
even if you run boot or lein clojure is still the compiler and runs the repl itself
2017-12-09T01:32:13.000003
Margaret
clojurians
clojure
so they might just "wrap" (1) and (2) from boot/lein instead of providing them as they do now
2017-12-09T01:32:26.000020
Jami
clojurians
clojure
they might - but you can run clojure 1.9 from lein or boot without clj
2017-12-09T01:32:47.000015
Margaret
clojurians
clojure
I see, but I'm curious how the boot/lein team will address the overlap
2017-12-09T01:35:59.000097
Jami
clojurians
clojure
they might find it useful, but they don't have to address it - everything still works the old way
2017-12-09T01:36:55.000065
Margaret
clojurians
clojure
what's the best way to get the distinct by value of a collection. `(?? [[:a 1] [:b 1] [:c 2] [:d 1]]) =&gt; [:c 2]`
2017-12-09T01:41:12.000077
Willow
clojurians
clojure
i've got some really gross partition by, filter, first, second, first threading going on
2017-12-09T01:41:47.000016
Willow
clojurians
clojure
maybe group-by, then test which values are 1 element long?
2017-12-09T01:42:46.000031
Margaret
clojurians
clojure
yeah but it ain't pretty ``` partitions (-&gt;&gt; edges (map (fn [kid] [(node-weight adjacency kid) kid])) (group-by first)) [size distinct-edge] (-&gt;&gt; partitions (filter (fn [[p-size nodes]] (= 1 (count nodes)))) first second first) ```
2017-12-09T01:43:21.000007
Willow
clojurians
clojure
was hoping there was a better way
2017-12-09T01:43:53.000028
Willow
clojurians
clojure
maybe some instead of filter but it's not much prettier
2017-12-09T01:44:51.000050
Willow
clojurians
clojure
```(-&gt;&gt; [[:a 1] [:b 1] [:c 2] [:d 1]] (group-by second) (filter (comp #{1} count val)) (first) (val) (first))```
2017-12-09T01:47:41.000009
Margaret
clojurians
clojure
that's certainly better
2017-12-09T01:48:21.000051
Willow
clojurians
clojure
i always forget about the #{1} style checking
2017-12-09T01:48:44.000045
Willow
clojurians
clojure
it's more fun to write, but there's also `#(= 1 (count (val %)))` which performs better
2017-12-09T01:49:41.000038
Margaret
clojurians
clojure
of course
2017-12-09T01:49:45.000044
Margaret
clojurians
clojure
what about (-&gt;&gt; [[:a 1] [:b 1] [:c 2] [:d 1]] (map reverse) (map vec) (into {})) =&gt; {1 :d, 2 :c}
2017-12-09T03:05:11.000055
Jami
clojurians
clojure
or `(-&gt;&gt; [[:a 1] [:b 1] [:c 2] [:d 1]] clojure.set/map-invert) =&gt; {1 :d, 2 :c}`
2017-12-09T03:08:05.000018
Jami
clojurians
clojure
Thanks <@Margaret>, I did start with `file-seq` but noticed it was based on `.listFiles` and since the laziness didn't seem to be an advantage to me used that directly. I've also tried an nio based approach. There's 458GB of files in on my file system and DaisyDisk is scanning that in ~13s, my approach doesn't complete in less than 15 mins (at which point I abort it).
2017-12-09T05:26:30.000076
Kayleigh
clojurians
clojure
I'm sure DD must be using something but cannot yet see how it might be the spotlight cache since my researches so far suggest that it doesn't contain a complete list of files on the file-system
2017-12-09T05:34:25.000040
Kayleigh
clojurians
clojure
I'm having a strange problem. I'm working on a problem from the advent of code, and I need to copy an input string from the webpage, and transform it into a data structure. A basic `(#{:a :b} :a)` comparison was returning nil, which prompted me to take a closer look at the result of the transformation. If I call `(transform raw-input-string)`, the printed result looks fine (and in fact, works fine!), but if I compare the printed result to the value returned by the function call `(= (transform raw-input-string) &lt;previous result&gt;)` I get `false`!
2017-12-09T07:08:51.000002
Mark
clojurians
clojure
I'm guessing there's some hidden special characters in there, that get dropped when the output is printed into the repl
2017-12-09T07:09:14.000058
Mark
clojurians
clojure
Is there a way to remove them..? I'm already removing non-breaking spaces, and using trim (which doesn't really do much I guess)
2017-12-09T07:09:43.000019
Mark
clojurians
clojure
I've tested this in cursive's repl inside Idea, lein's repl, and planck
2017-12-09T07:10:08.000025
Mark
clojurians
clojure
Eh, I `spit` the data structure into a file, and then `(-&gt; file slurp read-string)`
2017-12-09T07:25:26.000037
Mark
clojurians
clojure
And apparently the special characters are gone
2017-12-09T07:25:34.000041
Mark
clojurians
clojure
<@Mark> `(clojure.string/replace "your string" #"[^\p{Print}]" "")`
2017-12-09T07:26:36.000030
Heriberto
clojurians
clojure
or `(clojure.string/replace "your string" #"[^\x00-\x00]" "")` with range of characters (replace `00` with proper values)
2017-12-09T07:28:37.000025
Heriberto
clojurians
clojure
I tried the first one, I don't think it did anything. I'm probably not going to bother with the second one for now, since I got it working with that hacky file workaround. Appreciate the help though :slightly_smiling_face:
2017-12-09T07:30:22.000027
Mark
clojurians
clojure
I've never "installed Clojure" before (always used lein) but I was curious - is there an update for MacPorts rather than Brew ?
2017-12-09T07:46:21.000039
Beulah
clojurians
clojure
<@Beulah> <https://github.com/macports/macports-ports/blob/master/lang/clojure/Portfile>
2017-12-09T07:48:56.000120
Heriberto
clojurians
clojure
``` version 1.8.0 maintainers nomaintainer ```
2017-12-09T07:49:10.000034
Heriberto
clojurians
clojure
<@Heriberto> yeh I was thinking of Clojure 1.9 the latest
2017-12-09T07:50:57.000034
Beulah
clojurians
clojure
oh I see
2017-12-09T07:51:06.000170
Beulah
clojurians
clojure
I’m not sure what that is in MacPorts, but it’s not published by the Clojure core team
2017-12-09T08:04:28.000007
Sonny
clojurians
clojure
Hi, Clojurians! I have a question about Java Interop. I'm trying to translate some of the examples from [web3j](<https://docs.web3j.io/getting_started.html#start-sending-requests>) into Clojure. The synchronous requests work fine: ``` // Java Web3j web3 = Web3j.build(new HttpService()); Web3ClientVersion web3ClientVersion = web3.web3ClientVersion().send(); String clientVersion = web3ClientVersion.getWeb3ClientVersion(); ``` ``` ; Clojure (def http (new HttpService)) (def web3j (Web3j/build http)) (-&gt; web3j (.web3ClientVersion) (.send) (.getWeb3ClientVersion)) ; "Geth/v1.7.3-stable-4bb3c89d/linux-amd64/go1.7.3" ``` But my asychronous requests aren't working, and I think it has something to do with the Java 8 lambdas: ``` // Java Web3j web3 = Web3j.build(new HttpService()); web3.web3ClientVersion().observable().subscribe(x -&gt; { String clientVersion = x.getWeb3ClientVersion(); ... }); ``` ``` ; Clojure (def http (new HttpService)) (def web3j (Web3j/build http)) (defn callback [x] (println "received value:" x)) (-&gt; web3j (.web3ClientVersion) (.observable) (.subscribe callback)) ; CompilerException java.lang.IllegalArgumentException: No matching method found: subscribe for class rx.Observable ``` The [rx.Observable docs](<http://reactivex.io/RxJava/javadoc/index.html?rx/Observable.html>) say the subscribe method takes an argument of type Action1, which extends the Action interface, which extends the Function interface. Any ideas as to what I should be passing to a Java function that expects to receive a lambda? Thanks!
2017-12-09T10:30:51.000014
Alexander
clojurians
clojure
You need to use `reify` but I'm not sure which interface it's needed to implement here
2017-12-09T10:42:37.000006
Heriberto
clojurians
clojure
java lambdas are just syntactic sugar, at the bytecode level they're equivalent to anonymous classes there's no way to infer a conversion between clojure functions and Rx functions so you have to explicitly pass an instance of Rx expected type Action1
2017-12-09T10:43:51.000017
Rosia
clojurians
clojure
``` (def callback (reify Action1 (call [_ x] (println "received value:" x)))) ```
2017-12-09T10:44:40.000029
Rosia
clojurians
clojure
<@Rosia> <@Heriberto> Thanks! I will try this out and report back :thumbsup:
2017-12-09T10:48:31.000062
Alexander
clojurians
clojure
no, they are not anonymous classes <https://softwareengineering.stackexchange.com/questions/177879/type-inference-in-java-8/181743#181743>
2017-12-09T10:48:32.000104
Heriberto
clojurians
clojure
<@Rosia> After figuring out which class to import (it was `rx.functions Action1`), it worked flawlessly! Going to write up a blog post with my adventures when I have something a bit more substantial, and I will give you the credit for helping me out with this one. Thanks for the lesson!
2017-12-09T10:56:01.000120
Alexander
clojurians
clojure
thanks, I was unaware of that
2017-12-09T11:02:51.000004
Rosia
clojurians
clojure
<@Alexander> np but have look at <@Heriberto>’s link in the thread, my comment is inaccurate
2017-12-09T11:04:49.000044
Rosia
clojurians
clojure
I have a question; ```clojure (list? (cons 'do '((identity x) bla-bla))) =&gt; false | In Clojure =&gt; true | In Clojurescript ```
2017-12-09T11:14:37.000019
Olen
clojurians
clojure
What makes the difference ?
2017-12-09T11:15:11.000151
Olen
clojurians
clojure
I am sorry if it’s a newbie question or it’s obvious. But I really wondering, why…
2017-12-09T11:15:42.000060
Olen
clojurians
clojure
I always found it sneaky that a `cons` returns something that isn’t a `list?` in clj. It can trick you in situations like macros. Especially involving syntax quote because you don’t always know when it might return a `cons`. So really I end up just avoiding using `list?` for these sorts of things (so mostly just never use it)
2017-12-09T11:36:45.000044
Petronila
clojurians
clojure
It’s odd that cljs would be different though. I didn’t know that
2017-12-09T11:37:08.000137
Petronila
clojurians
clojure
Yea it did.
2017-12-09T11:37:12.000063
Olen
clojurians
clojure
So what are you using as a pred ?
2017-12-09T11:37:56.000120
Olen
clojurians
clojure
<@Petronila> often when you think you want `list?` the right predicate is `sequential?`
2017-12-09T11:38:16.000043
Margaret
clojurians
clojure
though that is true for vectors
2017-12-09T11:38:32.000040
Margaret
clojurians
clojure
Typically `sequential?`
2017-12-09T11:38:37.000024
Petronila
clojurians
clojure
Yeah if you don’t want vectors perhaps just `not` `vector?`
2017-12-09T11:39:14.000078
Petronila
clojurians
clojure
Oh, I did it right. :innocent:
2017-12-09T11:39:15.000039
Olen
clojurians
clojure
Yeah, I think that's a holdover from lisp? <@Petronila>
2017-12-09T11:39:36.000034
Sandy
clojurians
clojure
Seems like the real predicate is `seq?`, and sometimes `sequential?`
2017-12-09T11:39:55.000044
Sandy
clojurians
clojure
Often, outside of lisps, `list?` implies something that has O(1) counting.
2017-12-09T11:40:17.000098
Sandy
clojurians
clojure
you rock ! it's definitely a huge win for me, my benchmarks are almost on par with java with your patch.
2017-12-09T11:40:40.000143
Rosia
clojurians
clojure
<@Sandy> interesting. I’d have to check out something like Common Lisp to compare on that one.
2017-12-09T11:41:22.000024
Petronila