Fork me on GitHub
#beginners
<
2018-01-19
>
nulligor13:01:38

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?

sundarj13:01:11

also the other order:

(sort-by (complement :key) [{:key true} {:key false} {:key true} {:key false}])
({:key true} {:key true} {:key false} {:key false})

nulligor13:01:44

I was having trouble figuring out I'd have to use complement in this, thanks @rauh and @sundarj

sb15:01:49

Somebody know better solution than this? or nicer? (t/in-seconds (t/interval (c/from-long 1) (c/from-long 61037)))

sb15:01:27

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

sb15:01:23

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

matan15:01:35

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

matan15:01:50

Any ideas how to approach this?

matan15:01:57

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

noisesmith17:01:08

if you have no aot, lein compile should be a no-op

noisesmith17:01:17

I wouldn’t expect it to ever find any error

joshkh16:01:50

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?

gklijs16:01:01

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

joshkh16:01:48

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 ServerConnector@20276412{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)

joshkh16:01:34

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

joshkh16:01:56

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

joshkh16:01:46

would AOT have anything at all to do with it?

joshkh16:01:30

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.

joshkh17:01:54

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)

joshkh17:01:05

mystery solved, thanks

joshkh17:01:26

project.clj makes it into the uberjar but not the skinny jar, hence the reason we're only seeing the error now

ghadi18:01:42

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

jaide18: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.

ghadi18:01:26

when-some is just to handle the false

ghadi18:01:10

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

ghadi18:01:18

it's a tough problem

jaide18:01:24

I see, thanks!

rgorrepati18:01:15

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

jaide18:01:05

@rgorrepati The for each function doesn’t so could be a macro but the map function returns a channel though?

rgorrepati18:01:34

@jayzawrotny yep.. you are right

Omnis19:01:30

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.

nulligor19:01:08

there's usually a rainbow brackets plugin depending on your text editor @marcpianelli

timo19:01:15

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.

timo19:01:26

I want to do it like https://github.com/jacekschae/conduit but don't get the server-part

jaide20:01:22

Ack you’re right, my mistake! Though now I’m once again uncertain why that above snippet doesn’t work as expected.

justinlee20:01:30

@jayzawrotny its because you are taking from the channel returned by onto-chan instead of taking from c

jaide21:01:04

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

justinlee21:01:42

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

justinlee21:01:58

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

jaide21: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?

justinlee21:01:24

You should add an entry to clojuredocs for sure. I only started with clojure in december so I don’t know about community norms.

justinlee21:01:43

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

justinlee21:01:57

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”

jaide21: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.

justinlee20:01:39

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

justinlee20:01:15

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

felipebarros21:01:07

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?

lum22:01:29

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

lum22:01:01

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

justinlee23:01:35

@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

lum23:01:48

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)

lum23:01:19

I have the input fields and a button setup in html

lum23:01:04

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

lum23:01:36

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

justinlee23:01:01

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

lum23:01:25

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

justinlee23:01:29

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>

lum23:01:23

call it like .js/getElementById "something"?

justinlee23:01:24

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

justinlee23:01:46

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

lum23:01:15

and to set that <p>?

justinlee23:01:44

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

lum23:01:46

fine, this is just something very simple, just to start. Thank you very much @lee.justin.m

lum23:01:21

one more thing: after (.getElementById js/document "dia"), I get back #object[HTMLInputElement [object HTMLInputElement]]

lum23:01:39

how to get the contents of it?

noisesmith23:01:02

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

justinlee23:01:57

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

lum23:01:27

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

noisesmith23:01:47

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