This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-01
Channels
- # beginners (59)
- # cider (3)
- # clara (4)
- # cljsjs (4)
- # clojure (144)
- # clojure-finland (2)
- # clojure-italy (10)
- # clojure-russia (2)
- # clojure-spec (7)
- # clojure-uk (53)
- # clojurescript (81)
- # cursive (30)
- # datomic (36)
- # defnpodcast (2)
- # editors (3)
- # emacs (4)
- # events (1)
- # fulcro (12)
- # off-topic (11)
- # onyx (14)
- # parinfer (2)
- # pedestal (12)
- # re-frame (3)
- # reagent (26)
- # shadow-cljs (81)
- # spacemacs (10)
- # sql (59)
- # uncomplicate (4)
- # yada (4)
I made this function
(defn- apply-times
[a-fn v n]
(loop [res v
i 0]
(if (< i n)
(recur (a-fn res) (inc i))
res)))
to apply a function to a value x times and return the value itself, but I feel there is a canonical way to do this without creating a sequence?the alternative is something like (last (take 12 (iterate inc 0)))
ah right
I guess I generally have an aversion to generating sequences of functions 😮
Is there any function/macro that can create a map by just using the symbols as keys? I’m imagining a macro that might work like this: (->hash-map foo bar)
would expand to {:foo foo :bar bar}
I think I could make one but I just want to know if anyone has seen a macro that does this in clojure core
No. But this has come up as a question occasionally before and I believe it comes down to a syntax in JS that effectively allows this convenience? Is that where you're coming from?
(FWIW, I've almost never run into this situation where the work involved has been enough to make me yearn for a macro -- so I'm wondering how you're finding yourself in the position of wanting this...? Just curious)
I think I know what syntax your talking about but I didn’t get the idea from that. I’m destructuring a map and only taking some keys. I might use select-keys
for this sort of problem
select-keys
would be more idiomatic, I suspect. clojure.set/rename-keys
can also be useful (if you mostly need the same-named keys but a few need to be renamed).
Oh yea I forgot about that function. Not what I need in this instance as the keys are the same. Although I can recall times where I’ve wanted to do this
@tbaldridge hi tim - are you thinking of picking up odin again? i really like the idea of a generic edn data query language and odin seemed like a great step in that direction
@caleb.macdonaldblack are you aware of the :syms
keyword for destructuring that can be used in place of the much more common :keys
:
(let [{:syms [x y z]} {'x 1 'y 2 'z 3}]
[x y z])
;=> [1 2 3]
Ahh that’s quite handy. I’ve known of the :strs
but not :syms
Spec question - is there a way to get a minimal example from spec.gen?
@achythlook Can you explain what you mean?
s/exercise
will generate values from a spec -- and the first few will be pretty minimal. Is that not what you're after?
Not entirely. I'm aiming to generate a fairly complex entity map with several colls, and s/exercise spits out fairly large examples.
For reference, here's the file where I've defined the specs in question. https://github.com/Zaphodious/yushan/blob/master/src/com/blakwurm/lytek/spec.cljc
But the first example in the output of s/exercise
is going to be fairly minimal, yes?
Not in some tests that I've done here.
(first (s/exercise :lytek/solar))
spits out entities with various vectors of 20ish elements.Since that's driven by (pseudo) random generation and usually starts from near-minimal cases, I suspect you'd have to write custom generators to have more control over it... but I guess I'd ask, why do you want minimal cases? As long as they conform, why does it matter?
I'm building an API where people will be able to make a "new" entity of various types and subtypes. I was hoping to use this to make said entities rather then maintaining fresh examples by hand.
No major loss, as I can just run s/explain on my hand-maintained entities 🤷
Thanks anyway!
I used
lein deploy clojars
but I get the error gpg: signing failed: Inappropriate ioctl for device
Google searches for unfamiliar error message can sometimes turn up help. In this case, I found this page that might be helpful to you: https://github.com/keybase/keybase-issues/issues/2798
Hi, I was trying with https://github.com/relevance/labrepl but got into issues related with insecure HTTP warning when run $ lein deps is it me or the site itself is deprecated? Would anyone know to tell?
@U0U0HFT3J I had a similar problem last night with Leininingen version 2.7.1 and 2.8.1 commands when running with Oracle JDK 1.8.0_171. I installed Oracle JDK 1.8.0_181 and the problem went away. I do not know the cause of the problem, or the reason why updating my JDK made it stop.
Interesting, I thought it might be the issue where leiningen 2.8 does more rigorous checking of security certificates, but I just downloaded the labrepl repo and ran lein deps
with no problems or warnings.
I decided to write a simple fn/macro to do this, however, instead of getting something like:
(to-deps [org.clojure/clojure "1.9.0"])
=> {org.clojure/clojure {:mvn/version "1.9.0"}}
when I convert it to a map I get something like:
(to-deps [org.clojure/clojure "1.9.0"])
=> #:org.clojure{clojure #:mvn{:version "1.9.0"}}
this is my current naive implementation:
(defmacro to-deps [[sym version]]
`{'~sym {:mvn/version ~version}})
okay, it’s dumb but I guess this is solved by putting another value in the map that isn’t the same namespace:
(merge (to-deps [org.clojure/clojure "1.9.0"])
(to-deps [asdf/jkl "1.12.3"]))
=> {org.clojure/clojure #:mvn{:version "1.9.0"}, asdf/jkl #:mvn{:version "1.12.3"}}
so I can just add a dummy element to the map containing :mvn/version
as well :face_with_rolling_eyes: and find and replace
@lilactown those maps are the same map, this is just printing
namespace map syntax works for symbols too
you can get the keywords to print the classic way by doing (set! *print-namespace-maps* false)
{org.clojure/clojure {:mvn/version "1.9.0"}}
is same as #:org.clojure{clojure #:mvn{:version "1.9.0"}}
what I said above is correct
Yup, thanks for catching. Too bad the namespace map syntax biases your eyes towards keywords
yeah, for my case the literal output was important because my thinking was, “Oh I have like 20 leiningen dependencies. I’ll just write a quick clojure function/macro to convert it to deps.edn format and Eval-replace in my deps.edn”
okay, I looked at juxt/pack and depstar and didn’t see support for AOT compilation. it looks like badigeon might?
you can do it with depstar with a manual step if you compile
and then use jar -u
to put the AOT output back into the jar
okay so if I understand correctly, the order of operations is: 1. build uberjar (no AOT) 2. start uberjar (no AOT) 3. run clojure.core/compile 4. repack uberjar? 5. deploy uberjar (AOT)
I’m migrating an app that was already AOT compiling using leiningen - so if this basically does what lein uberjar
does then I should be 👍
Is there a recommended version of Java I should be using with Clojure? I know 1.8+ is required but I've heard there are potential issues with the latest version. I'm currently using OpenJDK 10 (Linux) and I get a reflection warning when I first connect over nREPL but haven't noticed anything else weird. But maybe there are other issues I may/likely come across in production?
@thiru0130 depending on your tools you may hit some issues, e.g. with cljr-refactor and/or pomegranate (dynamic loading of dependencies).
thanks for the heads up @U06BE1L6T .. I'm not using those.. I think I'll stick with v10 until it bites me 😕
I use OpenJDK 10 w CIDER/nREPL. no reflection warnings:
➜ git:(production) ✗ clj -A:dev:nrepl - <<EOM
(require 'cider-nrepl.main)
(cider-nrepl.main/init ["cider.nrepl/cider-middleware"])
EOM
nREPL server started on port 42585 on host localhost -
I would avoid Java 9 because it's sunsetted and CA cert bundle issues -- but either 8 or 10 should be fine. (Clojure 1.10 is dropping support for JDK <8)
a helpful JVM 9+ flag to see what is being naughty is: --illegal-access=debug
-- You'll get a stacktrace when something does illegal reflection (no exception thrown, but a printed trace)
Anyone got a good name for a function that behaves like this? Takes two vecs of things, returns a map where the keys are the first vec and the vals are whether or not that key is present in the second vec. so far I’m thinking something like isin-map
or zipmap-membership
but I’m not super sold.
(foo [1 2 3] [1])
{1 true, 2 false, 3 false}
@hiredman I’m using intersection in the function but I need the falsey values in the map as well. intersection will just give me the truthy values
the set of things is a dynamic list of options, so the front end doesn’t know ahead of time which options are available so it needs to be able to show the unselected things in order for a user to select them.
@lockdown- thanks - 🤞
in terms of style, is it normal to have a deftype
constructor with 8 positional parameters? I was just looking at the reagent code and I see (->Reaction f nil true false nil nil nil nil)
, which is incredibly hard to read (to my eyes), but I wonder if I’m missing something and how else it should have been done
I would have been inclined to pass an options map, but I feel like I’m missing something
deftype doesn't have a map constructor, but making a simple wrapper for the positional constructor is easy, and probably a good idea once you have more than 5 args
Anyone know of a library to connect to an nREPL server using clj CLI? I.e. not leiningen/boot
the clojure.tools.nrepl project has client code, you can use that via clj cli
also there's grenchman if what you want is a low overhead fast startup ready to go nrepl client (it's an ocaml program, but works with a clojure server just fine) https://github.com/technomancy/grenchman
thanks @noisesmith - I was hoping there would be something more built out like running lein repl :connect
do you need it to be a clojure process? because if no grenchman just works
you get a connection to the server
it's clojure
it's just that the client program is written in ocaml
right, it's a very small ocaml program that connects to clojure nrepl as a client
@thiru0130 your editor may have a nrepl client
there's that too
but grenchman is most certainly lighter weight and faster to start up than your editor :D
@lockdown- thanks but what I want really is just a simple clojure REPL separate from any editor but connected to an existing nREPL server. I want to use this to then start rebel-readline
doesn't rebel-readline need to directly control your terminal though?
maybe I don't understand what it's doing
so it looks like grenchman is using leiningen underneath so it won't work for me unfortunately
in that case you would need to build something yourself, connecting rebl-readline to an nrepl client
no, it can talk to any nrepl server - the lein part is optional
(that's intended as the main usage, but lein isn't needed for your use case)
@thiru0130 perhaps you could come up with a clojure
command-line invocation to achieve this...something like:
clojure -Sdeps '{:deps {nrepl ...}}' -e '(require 'nrepl) (nrepl/connect-to-server)'
Obviously those deps and functions need massaging, but something like that might be able to "bootstrap" into a more sophisticated environment.I really think having a clojure process that owns the terminal is the needed starting point for using rebel-readline, so either you wait for someone else to hook that up using clj and tools.nrepl client, or do it yourself
@cjsauer sure but does that hook up stdin to the remote repl?
thanks @cjsauer - but I think @noisesmith is right.. this seems to the be the hard bit (for me anyway).. handling edge cases, timeouts, exceptions etc.
what @thiru0130 wants is the glue that connects rebel-readline to a tty + stdin and connects it to a remote nrepl process instead of clojure in that same vm
the pieces all exist, but hooking it up isn't quite just legos
That's unfortunate as it seems almost fundamental...something like "sub-repls". Does the newer socket repl ease any pain? Or is this not at all nrepl specific?
@thiru0130 have you read https://github.com/clojure/tools.nrepl/blob/master/README.md#embedding-nrepl-starting-a-server ?
It looks like you can get a very stripped rebel-readline working inside an arbitrary REPL: https://github.com/bhauman/rebel-readline/blob/master/rebel-readline/src/rebel_readline/clojure/service/simple.clj
right, that's still talking to your in-vm clojure and not the remote though
@lockdown- they already have a remote, they need to talk to it
@noisesmith yeah, in that link, just below it says how to embed the client
right, and if you read further it shows the protocol etc.
bhauman is going to get to supporting nrepl eventually.. maybe just wait.. or try it myself 😮
I'm kind of lost in interceptors, I would like to log response status code and duration, how can I do that? (pedestal)
http://www.cs.yale.edu/homes/perlis-alan/quotes.html is a much better link