Fork me on GitHub
#clojure
<
2018-03-26
>
Garrett Hopper03:03:02

What are people's favorite symbols to use with as->? I kinda like (as-> _), but I'm curious what others' thoughts are.

Garrett Hopper03:03:32

(as-> 1 _
  (* _ 100)
  (/ _ 2)
  (str "100/2" "=" _))

Garrett Hopper03:03:41

It's definitely a deviation from the standard of _ being used for ignoring, which I suppose could lead to confusion.

dpsutton03:03:09

at work we always use <>. Its distinctive, most probably not conflicting with anything else

hiredman03:03:49

I've been using %

bronsa03:03:05

I use % too

Garrett Hopper03:03:05

Interesting, I haven't run into either of those.

bronsa03:03:20

_ seems like a bad choice to me

8
bronsa03:03:36

everywhere else _ means "ignore me"

👍 16
Garrett Hopper03:03:50

@bronsa That's the one thing I was concerned with.

bronsa03:03:32

sorry I didn't read the message where you say exactly that

Garrett Hopper03:03:53

Anyways, if anything thinks of other common symbols, please add them to that issue. I think it's worthwhile seeing what's most common.

Garrett Hopper03:03:14

@bronsa No worries; it's good to know that you had the same thought.

Garrett Hopper03:03:53

% is certainly growing on me. I didn't like it at first, due to possible confusion with anonymous functions, but it feels right.

bronsa03:03:08

I use it precisely because it recalls % from anon fns

dpsutton03:03:30

i guess you can't use anonymous functions in this then

arrdem03:03:27

you can - % in the context of #() is a reader macro so they don't conflict

dpsutton03:03:35

Hmm. I don't like that.

8
arrdem03:03:04

yeah it definitely looks goofy to me too but I haven't settled on anything better.

arrdem03:03:20

I agree that _ iss Not The Thing because that's for ignored values. I've seen some people use $ for the purpose.

Garrett Hopper14:03:22

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.

bronsa03:03:57

I mean, you generally don't do much HOF stuff in -> ime

bronsa03:03:44

so the shadowing issue with #() is not problem in practice more often than not

tbaldridge05:03:44

I’ve seen people use <> but I’m not crazy about that either.

Garrett Hopper14:03:07

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?

tbaldridge05:03:20

Bleh I don’t have backtick on my phone

tbaldridge05:03:44

That minus the space

arrdem06:03:31

yeah the old swiss-arrows library gave you -<> which was as-> <> and that worked but I agree with Tim didn't look great.

Garrett Hopper14:03:35

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.

Busy escaping the comfort zone07:03:57

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

hkjels07:03:58

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?

sundarj08:03:28

you can use it for all boolean values. i've seen it for boolean parameters, let bindings, and option map keys

sundarj08:03:37

=> (doc tree-seq)
-------------------------
clojure.core/tree-seq
([branch? children root])

hkjels09:03:24

OK, I’ve seen it as well, but thought it was a little counterintuitive. But if it’s expected I guess it’s fine

sundarj09:03:59

if you wanted to use it only for predicates in your own code, i don't think anyone would blink twice

👍 4
Ben Hammond08:03:55

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))))

Ben Hammond08:03:17

(dev/bar foo-impl-shim)
=> "beyond all repair"
as expected

Ben Hammond08:03:37

(dev/bar foo-impl)
java.lang.IllegalArgumentException: No implementation of method: :bar of protocol: #'dev/Foo found for class: clojure.lang.PersistentArrayMap
which seems unfortunate

Ben Hammond08:03:41

is this a side-effect of the way protocols are implemented, they always require a java Class?

Ben Hammond08:03:58

is there something I'm missing?

sundarj08:03:10

protocols are for type-based dispatch, not duck typing

Ben Hammond09:03:26

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

sundarj09:03:29

i'm not sure what your aim would be in doing that? protocols do single-dispatch on type; so you must specify a type

sundarj09:03:35

they don't mean anything other than that

Ben Hammond09:03:18

it's more a thought experiment

Ben Hammond09:03:39

but I would expect it to provide more runtime flexibility

sundarj09:03:55

protocols aren't for that kind of flexibility

sundarj09:03:01

multimethods are

sundarj09:03:39

from that doc link: "Support the 90% case of multimethods (single dispatch on type) while providing higher-level abstraction/organization"

Ben Hammond09:03:19

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

sundarj09:03:37

everything in Clojure turns into JVM classes/interfaces; protocols are no exception

sundarj09:03:39

more precisely, everything in Clojure gets compiled into JVM bytecode

Ben Hammond09:03:49

well yes, but there are often 'pure LISPier' ways to do stuff, as with derive parent/child hierarchies

Ben Hammond09:03:56

but not in this case

sundarj09:03:09

ah right, i see what you mean now

sundarj09:03:28

all of Clojure's types are JVM types; so anything to do with direct type-based dispatch is going to use those

sundarj09:03:37

if you want to use plain maps for dispatch, you can use multimethods

Ben Hammond09:03:39

yeah okay. thanks for your help

sundarj09:03:06

no prob 🙂

alexyakushev12:03:46

Does anyone know how to pass properties (like -Dclojure.compiler.disable-locals-clearing=true) to clojure wrapper script?

xtreak2912:03:18

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

schmee12:03:12

from what I gather from the docs, use -O:Dclojure.compiler.disable-locals-clearing=true

alexyakushev12:03:39

That doesn't work, unfortunately.

Alex Miller (Clojure team)12:03:01

should be -J-Dclojure.compiler.disable-locals-clearing=true

alexyakushev12:03:03

Made it work: clojure -J-Dclojure.compiler.disable-locals-clearing=true

Alex Miller (Clojure team)12:03:13

-O is for activating jvm opt aliases

alexyakushev12:03:37

Thanks Alex 🙂 For some reason, I first tried -JDclojure...

danielstockton14:03:56

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.

danielstockton14:03:23

Riemann being one such lib

bbss14:03:31

@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.

bbss14:03:20

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 🙂.

danielstockton14:03:31

Oh nice, my stuff started working with the ghaskins protobuf lib (i was using flatland version). Thanks!

🎉 4
danielstockton14:03:45

I think they've updated it to proto3 and it doesnt have a dependency on lein-protobuf anymore

bbss14:03:05

Good to hear! Smooth sailing from now on 🤞

🤞 4
Bravi15:03:37

hi everyone. what code editors / IDEs do you use for clojure?

danm15:03:07

Intellij IDEA + Cursive

danm15:03:59

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 😉

Bravi15:03:07

I think I’ve tried everything but can’t settle down with one 😄

Bravi15:03:35

I’m a vim guy and I’ve been using Spacemacs

schmee15:03:45

vim + vim-surround + vim-parinfer

danm15:03:59

There's a few vim guys in this team using... fireplace I think

michaels15:03:35

vscode + parinfer + Clojure (Lisin)

danm15:03:40

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

manuel15:03:57

Emacs+CIDER

Bravi15:03:02

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

bfay17:03:00

@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

Bravi09:03:30

Thank you, very nice theme indeed!

Bravi15:03:26

I’m considering Emacs now but I’m so used to vim keybindings, it’s so difficult to switch

Olical15:03:29

Emacs + Evil mode is what you want for the bindings

Olical15:03:44

I tried plain emacs but could never get it set up how I wanted it, I'm a Vim fan and settled on Spacemacs

Olical15:03:00

(may go back to Vim though some day soon...)

Michael Fiano16:03:41

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 😞

john16:03:55

I use nc and rebel-readline 😉

john16:03:32

Atom is coming along. I do most of my repl interactions outside the editor, so I just need convenient paren management in my editor

john16:03:25

I may try out zoakes nightlight thing sometime

dpsutton16:03:10

if you think spacemacs is ugly, you're not gonna like vanilla emacs

dpsutton16:03:25

but this might be better in #beginners

seancorfield16:03:26

There's also an #editors channel for general IDE/editor discuss...

cursive 4
tungsten17:03:57

do leiningen exclusions work for plugins?

lwhorton19:03:04

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) ...?

lwhorton19:03:29

I wish there was essentially something like fnil but more like … fnot-the-right-number-of-args?

mfikes19:03:00

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)]))))

lwhorton19:03:19

hehe, I’ll never be able to use juxt 😞

mfikes19:03:51

Oh... yeah, juxt is worth striving for, just because. 🙂

mfikes19:03:35

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)]))))

lwhorton20:03:00

hehehe, nice

elliot19:03:58

This seems interestingly related to Rich's dependency talk with the "give different/incompatible modules different names"

elliot19:03:25

As it seems to force the major/compatibility version number into being part of the name of the module

arrdem20:03:42

Not surprising. Pushing versions into the module system is kinda the only way to really get this right.

qqq21:03:55

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?

bronsa21:03:57

oh, TIL, I never noticed that optimization