This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-26
Channels
- # architecture (2)
- # beginners (310)
- # boot (34)
- # cider (50)
- # cljs-dev (82)
- # cljsrn (1)
- # clojure (125)
- # clojure-dusseldorf (1)
- # clojure-hamburg (1)
- # clojure-italy (47)
- # clojure-russia (21)
- # clojure-spec (38)
- # clojure-uk (36)
- # clojurescript (200)
- # community-development (21)
- # cursive (10)
- # datomic (15)
- # duct (58)
- # emacs (20)
- # fulcro (10)
- # funcool (1)
- # graphql (2)
- # hoplon (6)
- # jobs (1)
- # lumo (12)
- # mount (20)
- # off-topic (14)
- # om (5)
- # portkey (43)
- # protorepl (2)
- # re-frame (31)
- # reagent (36)
- # ring (17)
- # ring-swagger (6)
- # shadow-cljs (50)
- # spacemacs (9)
- # sql (5)
- # tools-deps (28)
- # uncomplicate (4)
- # unrepl (5)
- # vim (2)
- # yada (2)
What are people's favorite symbols to use with as->
? I kinda like (as-> _)
, but I'm curious what others' thoughts are.
(as-> 1 _
(* _ 100)
(/ _ 2)
(str "100/2" "=" _))
It's definitely a deviation from the standard of _
being used for ignoring, which I suppose could lead to confusion.
at work we always use <>
. Its distinctive, most probably not conflicting with anything else
Interesting, I haven't run into either of those.
@bronsa That's the one thing I was concerned with.
Anyways, if anything thinks of other common symbols, please add them to that issue. I think it's worthwhile seeing what's most common.
@bronsa No worries; it's good to know that you had the same thought.
%
is certainly growing on me. I didn't like it at first, due to possible confusion with anonymous functions, but it feels right.
I agree that _
iss Not The Thing because that's for ignored values. I've seen some people use $
for the purpose.
I'm coming to that conclusion. _
is too confusing.
Intersting, I haven't seen $
before, but I kinda like it. It feels like shell variables.
I’ve seen people use <> but I’m not crazy about that either.
I'm in the same boat. That seems like the best at the moment, but it still doesn't feel right. What do you currently use for this purpose?
Bleh I don’t have backtick on my phone
That minus the space
yeah the old swiss-arrows library gave you -<>
which was as-> <>
and that worked but I agree with Tim didn't look great.
Thanks for the link. I thought I'd seen a macro like this around somewhere. I've linked this in the discussion here https://github.com/bbatsov/clojure-style-guide/issues/164#issuecomment-376076167.
Hey Clojurians, I'm looking for a detailed reference for core.async I know about https://clojure.github.io/core.async/ and https://github.com/clojure/core.async/blob/master/examples/walkthrough.clj but looking for more detailed coverage
I’m uncertain about the convention to postfix with ?
. Would you use it with all boolean values or only predicate functions that return a bool
?
you can use it for all boolean values. i've seen it for boolean parameters, let bindings, and option map keys
=> (doc tree-seq)
-------------------------
clojure.core/tree-seq
([branch? children root])
OK, I’ve seen it as well, but thought it was a little counterintuitive. But if it’s expected I guess it’s fine
if you wanted to use it only for predicates in your own code, i don't think anyone would blink twice
can I treat a plain old function map as a protocol? I have this code
(defprotocol Foo
(bar [this]))
(def foo-impl
{:bar (fn [this] "beyond all repair")})
(def foo-impl-shim
(reify Foo
(bar [this] ((:bar foo-impl) this))))
(dev/bar foo-impl-shim)
=> "beyond all repair"
as expected(dev/bar foo-impl)
java.lang.IllegalArgumentException: No implementation of method: :bar of protocol: #'dev/Foo found for class: clojure.lang.PersistentArrayMap
which seems unfortunateis this a side-effect of the way protocols are implemented, they always require a java Class?
is there something I'm missing?
well I was wondering if there was some variant of
that would allow me to explicity connect a map with a protocol without having to specify AType
i'm not sure what your aim would be in doing that? protocols do single-dispatch on type; so you must specify a type
it's more a thought experiment
but I would expect it to provide more runtime flexibility
from that doc link: "Support the 90% case of multimethods (single dispatch on type) while providing higher-level abstraction/organization"
you might find this helpful: https://github.com/clojure-cookbook/clojure-cookbook/blob/49d1ce194bab4be689dae8006cab43427826590c/03_general-computing/3-09_polymorphism-with-protocols.asciidoc
so my lesson from that is
protocols are tightly coupled to java Classes and Interfaces due to the way that they manage their dispatch
And there's no getting away from it
well yes, but there are often 'pure LISPier' ways to do stuff, as with derive
parent/child hierarchies
but not in this case
all of Clojure's types are JVM types; so anything to do with direct type-based dispatch is going to use those
yeah okay. thanks for your help
besides reagent / reframe, what is the closest clojure lib to https://github.com/papers-we-love/papers-we-love/blob/master/design/out-of-the-tar-pit.pdf ?
Does anyone know how to pass properties (like -Dclojure.compiler.disable-locals-clearing=true
) to clojure
wrapper script?
https://clojure.org/reference/deps_and_cli > -O - JVM option aliases Allowed keys in these aliases are: :jvm-opts - a collection of string JVM options If multiple -O alias maps are activated, :jvm-opts concatenate If -J JVM options are also specified on the command line, they are concatenated after the alias options
from what I gather from the docs, use -O:Dclojure.compiler.disable-locals-clearing=true
should be -J-Dclojure.compiler.disable-locals-clearing=true
-O
is for activating jvm opt aliases
How are people using protobufs in their Clojure apps? Do you just compile the classes manually? clojure-protobuf et. al. don't really seem to be maintained anymore, and i'm always finding version conflicts with other libs that use protobufs.
Riemann being one such lib
@danielstockton Good question, and I echo your sentiment of unmaintained libraries. I am using protobuf in my starcraft II AI clj project. It's way hacky what I did.. But it works out in the end:
- I generated the java classes with the proto cli.
- Use the main (dated) repo that does clj<->java protobuf stuff '(org.clojars.ghaskins/protobuf "3.3.1-1")
It started giving me trouble with some of the used syntax in my the SC2 api proto files. Specifically some kind of enums/oneOf IIRC.
- Found/editted .ebnf
of .proto
and read all the proto specs. Turned those into Clojure.specs.
- Wrote a function that reads namespaced datastructures (based on these clojure.spec) and creates the related java builders and calls the setter methods, using reflection and string guessing of the method names..
- The deserializing works with the protobuf library, just not namespaced but that's okay.
code at: https://github.com/bbss/cljsc2 Some example of it in use: https://bbss.github.io/cljsc2/
Still working a lot on it. But the proto pain is gone and haven't had any issues with my hacky approach for a while. Spec is really awesome here. I can use cider to walk through the spec, even when that spec spans multiple files, can just walk the nodes 🙂.
Oh nice, my stuff started working with the ghaskins protobuf lib (i was using flatland version). Thanks!
I think they've updated it to proto3 and it doesnt have a dependency on lein-protobuf anymore
I already used it for Java, Ruby and Python, so finding a plugin that did Clojure as well was ace. Pity I had to pay extra for it though 😉
See http://blog.cognitect.com/blog/2017/1/31/clojure-2018-results in particular the 2nd section
In a former life I was a sys and net admin, so I prefer to keep my vim plugin free. Then I can just copy my .vimrc to any server and it works as I expect
I’ve tried that too, but I really really like the parens editing functionality in Spacemacs. it really speeds things up. but Spacemacs looks horrible 😄 no matter what theme I use, it’s just .. I don’t know
@U7ESY38HJ also use spacemacs, love it but agree that it looks pretty bad. If you like dark themes, have you tried sanityinc-tomorrow-bright
? It's in the themes-megapack
config layer. That one looks decent to me. The other sanityinc themes are okay, too
I’m considering Emacs now but I’m so used to vim keybindings, it’s so difficult to switch
I tried plain emacs but could never get it set up how I wanted it, I'm a Vim fan and settled on Spacemacs
I use both Emacs and Vim for a few different Lisp dialects including Clojure, and while I really love vim after using it for a couple decades, I will say that CIDER and the Emacs tools for working with Lisp are much better and more mature. So I tend to use both 😞
Atom is coming along. I do most of my repl interactions outside the editor, so I just need convenient paren management in my editor
I was so close to actually using juxt in a real scenario:
(defn abbrev-full-name [name]
(let [[fst sur] ((juxt first last) (clojure.string/split name #" "))]
(apply str fst " " (subs sur 0 1))))
(abbrev-full-name "luke horton")
=> "luke h"
(abbrev-full-name "luke w horton")
=> "luke h"
(abbrev-full-name "luke a bc def horton")
=> "luke h"
(abbrev-full-name "luke")
=> "luke l" ;;; noooooo!
Can anyone think up a functional way around this that doesn’t predicate on something cheesy like (if (< (count name) 2) ...
?I wish there was essentially something like fnil
but more like … fnot-the-right-number-of-args
?
I like how str
can ignore nil
, so when
inside str
is sometimes useful:
(defn abbrev-full-name [name]
(let [parts (clojure.string/split name #" ")]
(apply str (first parts)
(when-let [lst (last (rest parts))]
[" " (first lst)]))))
Here, using juxt
. It is always wort it
(defn abbrev-full-name [name]
(let [[fst sur] ((juxt first (comp last rest)) (clojure.string/split name #" "))]
(apply str fst (when sur [" " (first sur)]))))
This seems interestingly related to Rich's dependency talk with the "give different/incompatible modules different names"
As it seems to force the major/compatibility version number into being part of the name of the module
Not surprising. Pushing versions into the module system is kinda the only way to really get this right.
does [1 2]
waste 30 * 4 = 120 bytes of memory since we create an array that can hold 32 refs, but only use 2 of them?