This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-05-26
Channels
- # aws (7)
- # beginners (109)
- # boot (5)
- # carry (2)
- # cider (25)
- # clara (6)
- # cljs-dev (86)
- # cljs-experience (19)
- # cljsrn (1)
- # clojure (183)
- # clojure-dev (7)
- # clojure-dusseldorf (7)
- # clojure-gamedev (2)
- # clojure-greece (32)
- # clojure-italy (2)
- # clojure-norway (1)
- # clojure-russia (228)
- # clojure-sg (3)
- # clojure-spec (38)
- # clojure-uk (104)
- # clojurebridge (1)
- # clojurescript (29)
- # community-development (9)
- # core-async (118)
- # core-matrix (20)
- # cursive (5)
- # datomic (140)
- # emacs (25)
- # figwheel (1)
- # hoplon (21)
- # jobs (4)
- # lein-figwheel (2)
- # luminus (10)
- # lumo (35)
- # off-topic (137)
- # om (31)
- # onyx (62)
- # pedestal (6)
- # reagent (25)
- # remote-jobs (1)
- # ring-swagger (11)
- # spacemacs (2)
- # test-check (17)
- # uncomplicate (10)
- # unrepl (1)
- # untangled (20)
- # vim (4)
- # yada (3)
@noisesmith that only works in repl right?
right, there’s no lein command that does that
technomancy has been working on a new test runner though https://github.com/circleci/circleci.test
you can always create a lein command that runs a specific bit of clojure code in the context of your project (but at that point you would find it easier to use boot probably)
What is the right primitive for this: (1) I can always dereference OBJ to get latest value. (2) There is a "function" attached to OBJ< of type "old-state -> value -> new-state" (3) There is an incoming "stream of values", which must be processed, in order, exactly once. (4) the attached function is NOT guaranteed to be pure
I don't see a purity warning on add-watch. I'm fairly sure it will be called once and only once
You could probably piece together a core.async thing as well, but I find simple atoms to be easier for simpler problems.
Does someone have an idea how that could be done even faster with the help of reducers, if that's even possible?
Though pmap to me is very satisfying but, unfortunately codewars kinda doesn't like it Oo.
Hey aside from the official docs on the website and the youtube video from the language creator can anyone recommend good clojure tutorials for basic concurrent programming. Maybe a simple start project for concurrency
hi all, is there a nice browser automation lib out there? clj-webdriver is my last resort
I'm writing a lot of cljC lately. Is there a wa yto unify cljs.core.async anc clojure.core.async ?
@qqq Just try to require clojure.core.async
, it should rewrite it to cljs.core.async
, kinda recent feature
:refer now features macro inference. There is no longer any need to supply both :refer and :refer-macros in the same :require, the compiler will figure it out. clojure.* namespaces will now automatically be aliased to their ClojureScript equivalents. For example this means that the following is perfectly valid ClojureScript: -- oh man, those are awesome
We also have a new feature that is relevant for tooling such as Figwheel and cljs-devtools - :preloads. This should now be the standard way to inject some bit of side-effecting setup after core but before user code (i.e. connecting REPLs to standard ports, etc.). ^^ -- is there more detail on this feature ?
@qqq :preloads
documentation is at https://clojurescript.org/reference/compiler-options#preloads
I tried with aset-int, and profiling gives much worse results than with a simple aset
ah, i am misremembering. there's an int-map
datastructure but that appears to not be what you want
i thought i remembered it being holding integers, but it's holding integers as keys to the map
I could use a transient vector, I just want maximal performance bc it's pretty hot code
aset-int
is having to coerce to int
s, so i'm not surprised that it is slow. have you tried int-array
? i would benchmark the transient vector to see if meets your needs
yes the array is created with int-array
but I thought aset-int
was a kind of optimized version of aset
for native int arrays
this might be it: https://github.com/tmarble/webica
random thought: reverse destructuring would save a lot of boilerplate sometimes. (let [foo {:keys [bash bar baz]}]
what would that do?
would it be equivalent to (let [foo {:bash bash :bar bar :baz baz}] ...)
? because there’s a macro in flatland/useful that does that
I should really pull flatland/useful into my project
@dpsutton not just that - it also keys the map based on local binding names
something I find myself doing a lot when I refactor hairy functions
oh, to show value of locals - yeah I do that sometimes too (though I’ve found that for debugging putting the value in a vector inside an atom helps me fix things much faster… but I do the same “key is local name” hash map for that too so…)
yeah most of the clojure I write runs on a distributed system where there's no such thing as mutable state, step debugger, etc, so this might be a lot more common a pattern for me than most 😅
https://github.com/amalloy/useful was just mentioned above.
@bfabry same with mine - what I’m talking about is a top level def with (atom []) and then adding a swap! inside my function so that I store the data, then in the repl I can play with the data that is actually in play
it’s not any more work than adding logging is, and it’s a lot more useful
@matan I just look at the source
the namespaces are organized by the kind of thing they are good for (maps, namespaces, macros…)
@matan oh, btw, I have a work-in-progress lib to dump data from the repl to be used in unit tests (related to some ideas we talked about here about capturing data) https://github.com/noisesmith/poirot today I’m working on doing the same thing with cljs data (working around browser limitations makes that a little weird)
@noisesmith I will definitely have a look
it’s an intentionally tiny api - dump data from a repl, restore data inside a unit test (probably selecting and renaming the dump files in between via your OS)
@noisesmith LGTM!
One concern might be, avoiding a user unintentionally rewriting a data file already in use by a test. What do you think? maybe add some kind of warning or require an extra argument, for rewriting an existing one?
if you don’t specify a name, the default has a time stamp - but yeah, refusing to overwrite might be friendly
or just appending a number like the browser does
since it’s meant to be used interactively there’s room to be a little fiddly if needed
Yes I understand the point about fiddly. but say you add a test and rewrite a file created few months ago... some mortals may not realize they've altered an existing test file until they run the tests and analyze the errors
@noisesmith I might make a PR to allow modifying the target directory, after you flesh out some more of it of course
it uses env to set the target directory
(currently)
a planned direction for development is to get sane read-handlers and write-handlers for the common app data that isn’t in edn - stuff like atoms and refs - since I really do find myself needing to debug functions that take data with atoms in it sometimes
yep, good point, if this isn't much of a detour into bytecode detail or something like that .. I wonder how tractable that line of development might be
matan: it was actually easier than expected
peregrine.circle=> (p/dump (atom {:a 0 :b 1}))
"./test/data/class-clojure.lang.Atom-2017-05-26-12-33-15.transit.json"
peregrine.circle=> (p/restore *1)
#object[clojure.lang.Atom 0x4805de96 {:status :ready, :val {:a 0, :b 1}}]
I’ll have it pushed later@noisesmith Now that I try to play with it, I forgot how to make a dependency to a snapshot version. Are you pushing this to any public repository yet?
yeah - noisesmith/poirot
the latest version on github isn't deployed - cljs bugs
but you can play with it by running lein install
after cloning the repo
sorry, it's org.noisesmith/poirot https://clojars.org/org.noisesmith/poirot
transit supports custom tags, so it’s actually strightforward, it’s just a question of implementing it I think (see how it handles queus currently)
how common is the practice of putting your tests at the bottom of a source file actually ? i’ve never done this, but it seems to go very well with a repl-driven development style
Any reason lein uberjar
would be so slow when run inside the official Docker image? If I just create a new lein app, mount the directory into the container and docker run with lein uberjar, it takes much longer to complete the standalone.jar than it does directly on my Mac host. Using Docker for Mac fwiw. On any code that’s more involved than the hello world generated by lein new app, it seems to never finish.
is it downloading all the deps?
In the case of the hello world, there are none. In the larger case, I already have them baked in to an image extended from the official image
you always have deps, clojure.jar is a dep
In other words, it’s the time after the compilation is done and between X-SNASHOT.jar and X-SNAPSHOT-standalone.jar
It’s baffling. I wonder if it’s something with Docker for Mac in particular, but I don’t have a different setup to try.
# steps to recreate
lein new app docker-lein-uberjar
docker run -it --rm -v $(pwd)/docker-lein-uberjar:/checkout -w /checkout clojure:alpine lein uberjar
# output
Retrieving org/clojure/clojure/1.8.0/clojure-1.8.0.pom from central
Retrieving org/sonatype/oss/oss-parent/7/oss-parent-7.pom from central
Retrieving org/clojure/clojure/1.8.0/clojure-1.8.0.jar from central
Compiling docker-lein-uberjar.core
Created /checkout/target/uberjar/docker-lein-uberjar-0.1.0-SNAPSHOT.jar
# Relatively long pause
Created /checkout/target/uberjar/docker-lein-uberjar-0.1.0-SNAPSHOT-standalone.jar
are their any clojure libraries in need of a maintainer, also is there a programmatic way to figure this out? Building the tool to find this out might be kind of cool…
just getting started witih Clojure but prettier has made my life so much nicer that I already miss similar functionality when I work with other languages 🙂
There’s also zprint: https://github.com/kkinnear/zprint
cljfmt tends to err on the side of the user, changing wrong things but keeping the syntax otherwise. zprint, I believe, just formats everything the way it wants.
cljfmt was a game changer for me, it’s totally normal now to not check in code to our app unless we’ve fixed it with cljfmt and that solves so many annoyances
^^^ The real “problem” with using the same handle on github and slack and being prolific: whenever anyone mentions a library you wrote, you get summoned 🙂
ok, cool. Thanks. I actually think I'd prefer a way very opinionated formatter, especially because I'm totally new to lispy languages
this can get annoying. emacs is hard coded to scoot single ;
comments over to the right and cursive likes them at the beginning of the line
@dpsutton Cursive can be configured to move them over too: Settings->Editor->Code Style->Clojure->Comment alignment column
and it's how I use prettier with JS. I just let it fix everything on save. It's great for productivity, just let the tool fix formatting and focus on real issues
@pasi, what editor are you using?
atom for now (because it's what I use at work for everything else). I'm pretty flexible though
@pasi are you using parinfer?
pasi: Clojure programmers don't use IDEs, they use programmer's editors. Like emacs. ;)
@U0LGCREMU Except the ones that don’t, of course.
on Windows, Notepad++ is the fastest, greenest, autocompletion of the most convenient Clojure editor, with "Conemu + Lein repl + Dicom" is enough. Welcome to #notepad_plus_plus channel share files.
If you’re new to lispy languages, I’d recommend that.
There’s Cursive if you want a “real” IDE
Parinfer should handle the formatting of brackets for you, which is most of Clojure’s formatting right there 🙂
Yeah, Clojure demands a lot less in terms of linting than something like JS in the first place.
nod. I'll make a note of those formatters in case I still feel like I need one after getting hang of the syntax
pasi: Clojure programmers don't use IDEs, they use programmer's editors. Like emacs. ;)
@noisesmith You might be interested to learn that it is creating the uberjar, just very slowly. I monitored the file and it’s constantly growing. When I build the source into the image,it ran as fast as it usually does. It seems the speed issue is coming from when I mount the source as a volume and it’s having to compile a jar onto that host volume. More evidence it might be a bottleneck in docker.
is there a preferred pattern-matching library/macro? or an alternative that can solve similar problems? I'm trying to implement dispatch off of a set of actions that can be received in messages over ZMQ
multimethods and routers both work for simple dispatch with heirarchies
what kind of patterns do you think you’d be looking for in messages?
@noisesmith [<peer-id> "action" & args]
- I'd like to capture the peer id, and dispatch on action
I found matchure and have just now started an implementation using it, but it's quite old...
a defmulti can do that easily
I mean, if you prefer a matching lib that’s fine, and the clojure.core.match lib is probably the best maintained
but you do not need a full matcher and clojure.core can handle that
(defmulti zmq-message (fn [peer-id action & args] action)) (defmethod zmq-message "frob" [peer-id _ & args] …)
where “frob” is replaced by actual action string of course
this way different namespaces or optional submodules can make new message handling extensions too, which can be a nice way to grow a design sometimes
@noisesmith you can also do something similar with a case
statement
if they all have similar structure
that’s true
(let [[peer-id action & args] msg]
(case action
"foo" (do-foo peer-id args)
"bar" (do-bar peer-id args)))
yeah, it’s remarkable how similar a router, a hash-map, a multimethod, and a case statement can be sometimes