Fork me on GitHub

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


I use clj-time. I got the elapsed time in unix format (seconds).


Later I would like to get the mins too etc.. now I use just /1000 division.


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


Any ideas how to approach this?


As much as it matters, it's a library project (meaning, no main)


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}{}
[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 - / project.clj (No such file or directory)
        at Method)
        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)


i have no clue why or how project.clj is even relevant in that stack trace, especially since the server successfully started


thanks @gklijs i'll give that a read through again


would AOT have anything at all to do with it?


nvm that was a silly question

Alex Miller (Clojure team)16:01:29

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)


mystery solved, thanks


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

eccentric J18:01:45

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.


when-some is just to handle the false


side-effects of any sorts are prohibited by design in the channel mutex, but not enforced


it's a tough problem

eccentric J18:01:24

I see, thanks!


@jayzawrotny I think they could be a macros, because they don't return anything.

eccentric J18:01:05

@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 but don't get the server-part

eccentric J20:01:22

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

eccentric J21:01:04

Ohhhh! So the onto-chan function updates as a side effect and returns a channel that signifies when it’s finished?


it confused me too until removed the buffer to your channel and the program hung


the documentation is, um, let’s call it, um, terse

eccentric J21:01:01

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.


I have suspicion that they like things terse, but who knows?


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”

eccentric J21:01:35

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.


the channel returned by onto-chan just lets you know when it is done


change the $ on line 10 to c and i think it will do what you expected


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


have already set up clojuerescript + figwheel, any very small example on how to do this?


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


I have the input fields and a button setup in html


now, to read from the input fields, through their id attributes, how to do it?


I know nothing of React, do I really need it?


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>


call it like .js/getElementById "something"?


okay yea if you are familiar with that, you can just call (.getElementById js/document "myid")


or (js/document.getElementById "myid") works too and is more javascripty


and to set that <p>?


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


how to get the contents of it?


wouldn’t it be (.-innerHTML ...) since it’s a property?


oops! thanks yes. i still screw that up on a regular basis


do you mean: (def dia (.getElementById js/document "dia")) and then (.-innerHTML dia)?


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