This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-01-19
Channels
- # adventofcode (4)
- # beginners (80)
- # boot (4)
- # cbus (2)
- # cider (62)
- # clara (18)
- # cljs-dev (8)
- # cljsrn (10)
- # clojure (139)
- # clojure-brasil (3)
- # clojure-dev (27)
- # clojure-italy (1)
- # clojure-russia (3)
- # clojure-spec (4)
- # clojure-uk (47)
- # clojurescript (102)
- # core-async (10)
- # cursive (7)
- # datomic (71)
- # emacs (32)
- # fulcro (99)
- # funcool (1)
- # hoplon (3)
- # jobs (1)
- # jobs-discuss (6)
- # jobs_rus (2)
- # leiningen (3)
- # luminus (2)
- # lumo (14)
- # mount (7)
- # off-topic (19)
- # re-frame (25)
- # ring-swagger (4)
- # rum (3)
- # shadow-cljs (142)
- # specter (2)
- # sql (16)
- # timbre (1)
- # vim (3)
hello all!
supposing I have a vec of maps like [{:key false} {:key true}]
what would be the idiomatic way to sort it by truthyness of the key
index?
also the other order:
(sort-by (complement :key) [{:key true} {:key false} {:key true} {:key false}])
({:key true} {:key true} {:key false} {:key false})
I was having trouble figuring out I'd have to use complement
in this, thanks @rauh and @sundarj
Somebody know better solution than this? or nicer? (t/in-seconds (t/interval (c/from-long 1) (c/from-long 61037)))
Hi. It's been a while since I used clojure, and I forgot how to approach this:
I edit a source file with a deliberate syntax error to make sure the project is compiling, and lein check
spots the error whereas lein compile
seems to do nothing, it immediately returns without spotting the error
if you have no aot, lein compile should be a no-op
I wouldn’t expect it to ever find any error
in theory, if i deploy a clojure project to clojars, i should be able to include that jar as a dependency in a java project, right?
Yes, but you need a bit of stuff to make it usefull, and add least add the clojars repo, to the versioning system you use, so add a repository section and url in you pom.xml when using maven for example
so far it works and the clojure project (a web app server) is running from gradle. but when i try to access it via http i get an error about project.clj
missing...
[main] INFO org.eclipse.jetty.server.ServerConnector - Started [email protected]{HTTP/1.1}{0.0.0.0:5005}
[main] INFO org.eclipse.jetty.server.Server - Started @6161ms
18-01-19 13:53:59 kermit INFO [bluegenes.server:32] - Bluegenes server started on port: 5005
[qtp2091367901-32] WARN org.eclipse.jetty.server.HttpChannel - /
java.io.FileNotFoundException: project.clj (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at $fn__10968.invokeStatic(io.clj:229)
at $fn__10968.invoke(io.clj:229)
at $fn__10881$G__10874__10888.invoke(io.clj:69)
at $fn__10980.invokeStatic(io.clj:258)
https://clojure.org/reference/java_interop#_calling_clojure_from_java haven’t tried it myself yet
i have no clue why or how project.clj
is even relevant in that stack trace, especially since the server successfully started
yeah, that’s weird
clearly something is reading your project.clj. that seems a weird thing to do though.
yup, you're completely right. it looks like we're slurping in the project's version and providing it via an endpoint (for checking api compatibility)
project.clj makes it into the uberjar but not the skinny jar, hence the reason we're only seeing the error now
channel-for-each looks good (I've called this function sink or drain before). L6 when-let need to be when-some (because false
is a valid value to come over the channel.
channel-map has the disadvantage that the map-fn cannot be side-effecting because channels run transducers inside the "channel mutex"... which has restrictions
Ah cool! I’ll switch to when-some
but what would allow side-effects? In the stream world there’d be like a do
or tap
method that takes a fn to call with each value but always returns the initial input.
side-effects of any sorts are prohibited by design in the channel mutex, but not enforced
I see, thanks!
@jayzawrotny I think they could be a macros, because they don't return anything.
@rgorrepati The for each function doesn’t so could be a macro but the map function returns a channel though?
@jayzawrotny yep.. you are right
Hi guys, Is there any kind of resource that shows the organization of functions with color-coding, etc? I'm new to clojure/lisp and understand the syntax with simple functions. But for the higher-order stuff with functions of functions of functions, I get lost.
there's usually a rainbow brackets
plugin depending on your text editor @marcpianelli
has anyone a good example on how I create an easy login-form with sessions on luminus with re-frame? I am trying to grok that, but don't get it.
I want to do it like https://github.com/jacekschae/conduit but don't get the server-part
Are the docs wrong? It looks like the definition of it doesn’t actually return a channel https://github.com/clojure/core.async/blob/2afc2dc5102f60713135ffca6fab993fb35809f0/src/main/clojure/clojure/core/async.clj#L631
go-loop
is turned into a go
and loop
. you can see that go
returns a channel here
https://github.com/clojure/core.async/blob/68e4620a2daaa323595b7371e2692ebd204f7fba/src/main/clojure/cljs/core/async.clj#L4
Ack you’re right, my mistake! Though now I’m once again uncertain why that above snippet doesn’t work as expected.
@jayzawrotny its because you are taking from the channel returned by onto-chan instead of taking from c
Ohhhh! So the onto-chan
function updates as a side effect and returns a channel that signifies when it’s finished?
Good catch. I agree, the docs for this library are very terse. I’m fairly new to the community but is it welcomed if I created a pull request to update it? Or add an example to the clojuredocs entry?
You should add an entry to clojuredocs for sure. I only started with clojure in december so I don’t know about community norms.
if it weren’t for the fact that you can actually read and understand clojure source, I would have ditched it already because the documentation is lousy. but javascript was this way too, where the answers in the olden days were “read the source, luke”
Hah yeah, that’s fair. The answer is technically there, I guess I was just slow on the uptake that a.) go-loop returns a channel b.) the channel it returns is obviously not going to be the one we’re pushing onto.
I want to build a static website and I'm a beginner. Does anybody have a tip on a simple (beginner-friendly) and elegant tool?
hi there, first very small task with clojurescript. Have a html with forms to be filled by numbers, calculate some numerical operation based on them and return the result to be printed in the html
@lum could you back up and explain what you are trying to do, because it kind of sounds like you are asking how to do basic frontend web design, but maybe i misunderstand you
hi @lee.justin.m, I've been learning Clojure, but need to do this very basic ClojureScript "project". A user writes some numbers in html <input> fields, and after some calculation done, some result should be printed in the same html page, in some part of it (<p> for example)
@lum try this tutorial https://github.com/jonase/reagent-tutorial
you need something to manipulate the dom. your only other real choice is direct calls to the dom (not recommended) or maybe something like jquery. but really, you can get the hang of reagent without knowing react for something as simple as what you are trying to do
ok, I've done some javascript some years ago, and could access (and set) the DOM directly, thought could do it with no problems in ClojureScript as well
if it is truly dead simple, you could put an empty <p> in your webpage and then, in your form’s onsubmit handler, call getElementById on it and put something inside that <p>
okay yea if you are familiar with that, you can just call (.getElementById js/document "myid")
actually i don’t know the dom calls very well, i’m sure you can google them on mdn. they work exactly the same in clojurescript
fine, this is just something very simple, just to start. Thank you very much @lee.justin.m
one more thing: after (.getElementById js/document "dia"), I get back #object[HTMLInputElement [object HTMLInputElement]]
(.innerHTML ...)
checkout https://developer.mozilla.org/en-US/docs/Web/API/Element
wouldn’t it be (.-innerHTML ...)
since it’s a property?
right but in real code you probably wouldn’t put that in a def. You can do it in one expression with (->> "dia" (.getElementById js/document) (.-innerHTML))